xslt - Merge two xml ... again -


my knowledge xslt limited, i've googeled hours , trying many different scripts without luck. here plot: have xml database file on our server software read every time start software. 10 users use file. new entries stored in similar file locally, , need update server file include our new locally stored entries weekly. have made upload feature upload local files. uploaded file stored in directory above database file. name same both files, stored in different directories.

here closest thing i've come with, copying former solutin site, changing names. exemple files here few entries testing purpose only.

"original" xml: companyroutes.xml

 <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xml" href="merge2.xsl"?>  <companyroutes>   <route name="engmekch">engm oksat l996 svd ekch</route>  </companyroutes> 

uploaded xml: /upload/companyroutes.xml

<?xml version="1.0" encoding="utf-8"?> <companyroutes>    <route name="envaenbr">enva gevli z108 roxet enbr</route>    <route name="engmekch">engm oksat l996 svd ekch</route>    <route name="abcdefgh">abcd tulla l666 baren efgh</route>  </companyroutes> 

here xsl merge script: merge2.xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">   <xsl:output method="xml" indent="yes"/>   <xsl:param name="filename" select="'/upload/companyroutes.xml'" />   <xsl:param name="updates" select="document($filename)" />    <xsl:variable name="updateroute" select="$updates/companyroutes/route" />    <xsl:template match="@* | node()">     <xsl:copy>       <xsl:apply-templates select="@* | node()"/>     </xsl:copy>   </xsl:template>    <xsl:template match="companyroutes">     <xsl:copy>       <xsl:apply-templates select="route[not(@id = $updateroute/@id)]" />       <xsl:apply-templates select="$updateroute" />     </xsl:copy>   </xsl:template> </xsl:stylesheet> 

two other functions need included unique childs beeing copied original , ability still view original file in browser today on url: [http://www.xxxxx.org/cr/companyroutes.xml][1] when have tried inserting link second .xsl file doing merging, cannot see info on url.

here cr.xsl transfor xml html table on webpage:

<?xml version="1.0" encoding="iso-8859-1"?>  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">  <xsl:template match="/">   <html>   <body>   <h2>bbl - companyroutes</h2>   <table border="1" cellspacing="0" cellpadding="2">     <tr>       <th>route name</th>       <th>route</th>     </tr>     <xsl:for-each select="//route">     <tr>       <td><xsl:value-of select="./@name"/></td>       <td><xsl:value-of select="./text()"/></td>     </tr>     </xsl:for-each>   </table>   </body>   </html> </xsl:template>  </xsl:stylesheet> 

you have 2 problems here.

firstly, in merge xslt doing this

<xsl:apply-templates select="route[not(@id = $updateroute/@id)]" />  

you matching on @id attributes, in xml appears @name attribute should used. therefore statement should

 <xsl:apply-templates select="route[not(@name = $updateroute/@name)]" />  

you talk viewing in browser, , looking @ xml have linked to, have 2 xml-stylesheet processing instructions @ top of xml (although show 1 in xml sample in question)

<?xml-stylesheet type="text/xsl" href="cr.xsl"?> <?xml-stylesheet type="text/xml" href="merge2.xsl"?>  

this suggests may expecting 2 transformations applied. cr.xsl applying result of merge2.xsl transformation. not believe possible in way. if possible, not overwrite original xml. creating whole new xml document display.

what can do, merge 2 xslt stylesheets one, , use that, if purely want see results of merge in browser

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">   <xsl:param name="filename" select="'upload.xml'"/>   <xsl:param name="updates" select="document($filename)"/>    <xsl:variable name="updateroute" select="$updates/companyroutes/route"/>    <xsl:template match="companyroutes">     <html>       <body>         <h2>bbl - companyroutes</h2>         <table border="1" cellspacing="0" cellpadding="2">           <tr>             <th>route name</th>             <th>route</th>           </tr>           <xsl:for-each select="route[not(@name = $updateroute/@name)]|$updateroute">             <xsl:sort select="@name"/>             <tr>               <td>                 <xsl:value-of select="./@name"/>               </td>               <td>                 <xsl:value-of select="./text()"/>               </td>             </tr>           </xsl:for-each>         </table>       </body>     </html>   </xsl:template> </xsl:stylesheet> 

of course, if did want overwrite original xml merge, not possible using approach. adding xml-stylesheet processing instructions in xml not cause original xml overwritten in anyway. (bear in mind transformation being done on client, in browser, files being stored on server.)

you going have investigate doing transformations on server, using server language such php, or asp.net, or else, depending on architecture using.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -