This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
How to perse the whole source document
- To: <XSL-List at lists dot mulberrytech dot com>
- Subject: [xsl] How to perse the whole source document
- From: "Mohammed Rahman" <mrahman at planlinx dot com>
- Date: Fri, 25 May 2001 16:48:29 -0700
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi all,
Hi Jeni!
I have the source xml (file 1) like this:
<article>
<section name="S01">
<para seq="P01.01"> aaa </para>
<para seq="P01.01"> bbb </para>
<para seq="P01.02"> xxx </para>
<para seq="P01.02"> yyy </para>
<section name="S01.01">
<para seq="P01.01.01"> mmm </para>
<para seq="P01.01.01"> nnn </para>
<para seq="P01.02.01"> ppp </para>
<para seq="P01.02.01"> rrrr </para>
</section>
</section>
</article>
XML file 2:
<TableName>
<RecordName>
<P01.01>
<path> path1 </path>
<cat> category1 </cat>
<P01.01>
</RecordName>
<RecordName>
<P01.01.01>
<path> path2 </path>
<cat> category2 </cat>
<P01.01.01>
</RecordName>
</TableName>
My XSL look like this:
<?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="/">
<xsl:apply-templates />
</xsl:template>
-->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="section">
<sid>
<xsl:apply-templates select="*[1]" mode="merge" />
</sid>
</xsl:template>
<xsl:template match="*" mode="merge">
<xsl:copy-of select="." />
<xsl:apply-templates select="following-sibling::*[1]" mode="merge" />
</xsl:template>
<xsl:template match="para" mode="merge">
<xsl:variable name="as" select="@name" />
<text name="{@name}">
<xsl:apply-templates select="." mode="content" />
<xsl:copy-of select="document('doc2.xml')
/TableName/RecordName[normalize-space(name) =
$as]
/*[not(self::name)]" />
</text>
<xsl:apply-templates mode="merge"
select="following-sibling::para[@name != current()/@name][1]" />
</xsl:template>
<xsl:template match="para" mode="content">
<xsl:copy-of select="node()" />
<xsl:text>
</xsl:text>
<xsl:apply-templates mode="content"
select="following-sibling::*[1][@name = current()/@name]" />
</xsl:template>
</xsl:stylesheet>
The out put comes like this:
<article>
<sid>
<text name="P01.01">aaa bbb
<path>path1</path>
<cat>cattegory1</cat>
</text>
</sid>
</article>
Now my question is why does not it perse the whole document? In other words
I expect my resulting xml as to be:
<article>
<sid>
<text name="P01.01">aaa bbb
<path>path1</path>
<cat>cattegory1</cat>
</text>
<sid>
<text name="P01.01.01">mmm nnn
<path>path2</path>
<category>cattegory2</category>
</text>
</sid>
</sid>
</article>
But I do not get it....
Please help. Thank you all in advance.
Regards,
Mo
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list