XSLT for XML to XML quandary -


i have been assigned new project use xslt stylesheet convert 1 xml document xml format.

i have spent last 4 hours trawling through archives on stackoverflow , elsewhere online try find out how achieve desired results, nothing can find points me right direction.

here's original document format:

<?xml version="1.0"?> <podordersheet_main>     <estimate>         <customer>linfnc</customer>         <jobtype>5020</jobtype>         <jobparts>             <jobpart>                 <jobpart>01</jobpart>                 <contactnum/>                 <jobnotes>                     <jobnote>                         <department>001</department>                         <jobpart>01</jobpart>                         <note><![cdata[rush order]]></note>                     </jobnote>                 </jobnotes>             </jobpart>         </jobparts>     </estimate>     <estimate>         <customer>linfnc</customer>         <jobtype>5020</jobtype>         <jobparts>             <jobpart>                 <jobpart>01</jobpart>                 <contactnum/>                 <jobnotes>                     <jobnote>                         <department>001</department>                         <jobpart>01</jobpart>                         <note><![cdata[rush order]]></note>                     </jobnote>                 </jobnotes>             </jobpart>         </jobparts>     </estimate>     <estimate>         <customer>linfnc</customer>         <jobtype>5020</jobtype>         <jobparts>             <jobpart>                 <jobpart>01</jobpart>                 <contactnum/>                 <jobnotes>                     <jobnote>                         <department>001</department>                         <jobpart>01</jobpart>                         <note><![cdata[rush order]]></note>                     </jobnote>                 </jobnotes>             </jobpart>         </jobparts>     </estimate> </podordersheet_main> 

and here how needs look:

<?xml version="1.0" encoding="utf-8"?> <!doctype estimate> <estimate>     <customer>linfnc</customer>     <jobtype>5020</jobtype>     <jobparts>         <jobpart>             <jobpart>01</jobpart>             <contactnum/>             <jobnotes>                 <jobnote>                     <department>001</department>                     <jobpart>01</jobpart>                     <note><![cdata[rush order]]></note>                 </jobnote>             </jobnotes>         </jobpart>         <jobpart>             <jobpart>02</jobpart>             <contactnum/>             <jobnotes>                 <jobnote>                     <department>001</department>                     <jobpart>02</jobpart>                     <note><![cdata[rush order]]></note>                 </jobnote>             </jobnotes>         </jobpart>         <jobpart>             <jobpart>03</jobpart>             <contactnum/>             <jobnotes>                 <jobnote>                     <department>001</department>                     <jobpart>03</jobpart>                     <note><![cdata[rush order]]></note>                 </jobnote>             </jobnotes>         </jobpart>     </jobparts> </estimate> 

i'm able copy on elements without problems. i'm getting stuck need first occurrence of customer , jobtype elements, of included jobparts multiple estimate blocks, numbered correctly in order fall in jobpart element.

i'd appreciative if point me in right direction on project i'm not getting anywhere on own.

this doesn't appear me grouping problem. far can see need first customer , jobtype elements copied beginning of output. thereafter it's copy of jobpart elements. jobpart (with small j - nasty gotcha waiting there) elements own template number them according the containing jobpart elements in source data.

this transform seems need

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet     xmlns:xsl="http://www.w3.org/1999/xsl/transform"     version="1.0">      <xsl:strip-space elements="*"/>     <xsl:output method="xml" indent="yes"/>      <xsl:template match="@*|node()">         <xsl:copy>             <xsl:apply-templates/>         </xsl:copy>     </xsl:template>      <xsl:template match="/podordersheet_main">         <estimate>             <xsl:copy-of select="estimate[1]/customer"/>             <xsl:copy-of select="estimate[1]/jobtype"/>             <jobparts>                 <xsl:apply-templates select="estimate/jobparts/jobpart"/>             </jobparts>         </estimate>     </xsl:template>      <xsl:template match="jobpart">         <xsl:copy><xsl:number count="jobpart" level="any" format="01"/></xsl:copy>     </xsl:template>  </xsl:stylesheet> 

output

<?xml version="1.0" encoding="utf-8"?> <estimate>    <customer>linfnc</customer>    <jobtype>5020</jobtype>    <jobparts>       <jobpart>          <jobpart>01</jobpart>          <contactnum/>          <jobnotes>             <jobnote>                <department>001</department>                <jobpart>01</jobpart>                <note>rush order</note>             </jobnote>          </jobnotes>       </jobpart>       <jobpart>          <jobpart>02</jobpart>          <contactnum/>          <jobnotes>             <jobnote>                <department>001</department>                <jobpart>02</jobpart>                <note>rush order</note>             </jobnote>          </jobnotes>       </jobpart>       <jobpart>          <jobpart>03</jobpart>          <contactnum/>          <jobnotes>             <jobnote>                <department>001</department>                <jobpart>03</jobpart>                <note>rush order</note>             </jobnote>          </jobnotes>       </jobpart>    </jobparts> </estimate> 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -