Page 1 of 1

xsl attribute value(pre order and post order)

Posted: Wed Apr 06, 2005 5:59 pm
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

Posted: Wed Apr 06, 2005 7:20 pm
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

In order

Posted: Sat Apr 09, 2005 8:04 pm
by sxxx
Thanks for the style sheet.. i would like to know what do u mean by printing the id values in order??