xsl attribute value(pre order and post order)

Here should go questions about transforming XML with XSLT and FOP.
sxxx
Posts: 6
Joined: Sun Mar 27, 2005 10:29 pm

xsl attribute value(pre order and post order)

Post by sxxx »

Hi all,

I have a small problem on xsl..i need to design an xsl stylesheet to output one line for each element, in preorder and postorder, which contains the id values for the element and its successor and predecessor.

Code: Select all


  <!DOCTYPE document (View Source for full doctype...)> 
- <document id="d">
- <chapter id="dc1">
- <section id="dc1s1">
<topic id="dc1s1t1" />
<topic id="dc1s1t2" />
</section>
- <section id="dc1s2">
<topic id="dc1s2t1" />
<topic id="dc1s2t2" />
</section>
</chapter>
- <chapter id="dc2">
- <section id="dc2s1">
<topic id="dc2s1t1" />
<topic id="dc2s1t2" />
</section>
- <section id="dc2s2">
<topic id="dc2s2t1" />
<topic id="dc2s2t2" />
</section>
</chapter>
</document>
thanks
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Something like below:

Code: Select all


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:text>Pre-order
</xsl:text>
<xsl:apply-templates select="." mode="pre"/>
<xsl:text>Post-order
</xsl:text>
<xsl:apply-templates select="." mode="post"/>
</xsl:template>


<xsl:template match="*" mode="pre">
<xsl:call-template name="display"/>
<xsl:apply-templates mode="pre"/>
</xsl:template>
<xsl:template match="text()" mode="pre"/>



<xsl:template match="*" mode="post">
<xsl:apply-templates mode="post"/>
<xsl:call-template name="display"/>
</xsl:template>
<xsl:template match="text()" mode="post"/>

<xsl:template name="display">
<xsl:text>[</xsl:text>
<xsl:value-of select="preceding::*/@id"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="@id"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="following::*/@id"/>
<xsl:text>]</xsl:text>
<xsl:text>
</xsl:text>
</xsl:template>

</xsl:stylesheet>
Regards,
George
sxxx
Posts: 6
Joined: Sun Mar 27, 2005 10:29 pm

In order

Post by sxxx »

Thanks for the style sheet.. i would like to know what do u mean by printing the id values in order??
Post Reply