|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XML/XSLT Problem
Hi Alex,
test if this stylesheet meets your expectations: <xsl:template match="abc">
<xsl:copy>
<xsl:apply-templates select="PP"/>
</xsl:copy>
</xsl:template><xsl:template match="PP">
<Group>
<xsl:copy-of select="."/>
<xsl:apply-templates select="../IP[@id = current()/IPI/@id]"/>
</Group>
</xsl:template><xsl:template match="IP">
<xsl:copy-of select="."/>
<xsl:apply-templates select="../PR[@id = current()/@id-1]"/>
</xsl:template><xsl:template match="PR">
<xsl:copy-of select="."/>
</xsl:template>XML input <abc>
<PP id="111" id-1="222" >
<IPI id="333" id-2="444" >
<p1>p1p1p1</p1>
</IPI>
<IPI id="sss" id-2="666" >
<p1>p2p2p2</p1>
</IPI>
</PP>
<PP id="777" id-1="888" >
<IPI id="123" id-2="234" >
<p1>p3p3p3</p1>
</IPI>
<IPI id="456" id-2="567" >
<p1>p4p4p4</p1>
</IPI>
</PP>
<IP id="rrr" id-1="aaa">
<i1>i1i1i1</i1>
</IP>
<IP id="sss" id-1="bbb">
<i1>i2i2i2</i1>
</IP>
<IP id="ttt" id-1="ccc">
<i1>i3i3i3</i1>
</IP>
<IP id="uuu" id-1="ddd">
<i1>i4i4i4</i1>
</IP>
<PR id="xxx">
<r1>r1r1r1</r1>
</PR>
<PR id="bbb">
<r1>r2r2r2</r1>
</PR>
<PR id="zzz">
<r1>r3r3r3</r1>
</PR>
</abc>XML output <abc>
<Group>
<PP id="111" id-1="222">
<IPI id="333" id-2="444">
<p1>p1p1p1</p1>
</IPI>
<IPI id="sss" id-2="666">
<p1>p2p2p2</p1>
</IPI>
</PP>
<IP id="sss" id-1="bbb">
<i1>i2i2i2</i1>
</IP>
<PR id="bbb">
<r1>r2r2r2</r1>
</PR>
</Group>
<Group>
<PP id="777" id-1="888">
<IPI id="123" id-2="234">
<p1>p3p3p3</p1>
</IPI>
<IPI id="456" id-2="567">
<p1>p4p4p4</p1>
</IPI>
</PP>
</Group>
</abc>If the file is much bigger and you have to compare many elements by their @id's, it's better to setup keys and use them for faster element access. Regards, Joerg Alex Genis wrote: Hi, G.Ken. Thanks a lot for your help. Your XSLT works perfectly. But this is not exactly what I was looking for (maybe because I've described my task not clear enough). XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








