XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Bob FosterSubject: xslt child selections
Author: Bob Foster
Date: 15 Dec 2006 04:58 PM
Hello all,
Is there a away in xslt to apply template rules to all children of a given node? I have xml docs with a structure of


<row>
<field1>
<field2>
<field3>
...etc
</row>


The <row> tag is common to each doc but the child nodes may have different names. I'd like to have one xslt stylesheet handle all of them if possible. How would I select or loop through every child node of the <row> tag? Thanks in advance! :)

Postnext
Ivan PedruzziSubject: xslt child selections
Author: Ivan Pedruzzi
Date: 15 Dec 2006 05:12 PM
You can either use

<xsl:-apply-templates/>

or

<xsl:for-each select="*">
...
</xsl:for-each>


Ivan Pedruzzi
Stylus Studio Team

Postnext
Bob FosterSubject: xslt child selections
Author: Bob Foster
Date: 15 Dec 2006 07:22 PM
So are you saying it would be something like:

<xsl:template-match = "row"/>

and then:

<xsl:for-each select = "*"/>

apply rules

</xsl:for-each>

...in order to access the children of the row nodes? (The row is not the root of the doc in this case)

Thanks, Ivan

Postnext
Bas ReteraSubject: xslt child selections
Author: Bas Retera
Date: 16 Dec 2006 08:54 AM
You can use something like this:

<xsl:template match="row">
<xsl:for-each select="child::node()">
<xsl:call-template name="child_node"/>
</xsl:for-each>
</xsl:template>

<xsl:template name="child_node">
....
</xsl:template>

Posttop
Bob FosterSubject: xslt child selections
Author: Bob Foster
Date: 18 Dec 2006 03:51 PM
Thanks for your help, everyone. It turns out I was making things too complicated. I just used :


<xsl:template match = "row">
<div class = 'rowCount'>
<xsl:for-each select = "text()">
<div class = 'field'>
<xsl:value-of select = "."/>
</div>
</xsl:for-each>
</div>
</xsl:template>


...which grabs the value from each child node of the <row> tag and puts it in its own div. Thanks again!

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.