Jump to content

Output All Nodes In Order


Digga

Recommended Posts

HiPlease bear with me, I've just dipped my toe in the XSLT waters and regardless what I do I cannot output the following XML in order, I always get grouped nodes - categories then fields.Here's a sample of the XML:

<form>  <category name="Content" />  <field column="QueryName" value="1" />  <category name="Content filter" />  <field column="OrderBy" value="123" />  <field column="TransformationName" value="45" />  <field column="DetailTransformationName" value="76" />  <field column="AlternatingTransformationName" value="88" />  <category name="Layout" />  <field column="RepeatColumns" value="44" />  <field column="RepeatDirection" value="36" />  <field column="RepeatLayout" value="77" /></form>

And here's the output I would like to see:Category Name: ContentField: Column: QueryName Value: 1Category Name: Content filterField: Column: OrderBy Value: 123Field: Column: TransformationName Value: 45Etc.The output is a sample and would get me going in the right direction. I just need to process each in the order found in the XML file.Many thanks in advance for any advice and guidance for this newbie would be very much appreciated.Digga

Link to comment
Share on other sites

The nodes are processed in document order anyway, unless you used xsl:sort. So simply write templates for the category and field elements outputting what you want:

<xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0">    <xsl:strip-space elements="*"/>  <xsl:output method="text"/>    <xsl:template match="form/category">	<xsl:value-of select="concat('Category Name: ', @name, '')"/>  </xsl:template>    <xsl:template match="form/field">	<xsl:value-of select="concat('Field: Column: ', @column, ' Value: ', @value, '')"/>  </xsl:template> </xsl:stylesheet>

Note: the '' in the code sample should be '& # 1 0;', only without the spaces.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...