getting all the children of the context node
Posted: Wed May 27, 2009 5:31 pm
I have a source document that represents a book it has a sec (section) node that can have nodes named title, p, and list. I am doing a <xsl:for-each select="/article/body/sec"> to get each section. I would like to (and I have not been able to) get all the children nodes for each section (the titles, the ps, and the lists) with an <xsl:for-each select= . My plan is to do that and then, within the for-each, do <xsl:choose and <xsl:when 's to output the stuff the way I want it - depending on if I have a title, p, or list at the moment.
Once I am on the sec node, how do I get all the children nodes? TIA.
Following are the source document fragments and the xslt fragment.
Source ========================================================
<?xml version="1.0" encoding="UTF-8"?>
<article>
<body>
<sec sec-type="intro">
<title>Introduction</title>
<p>Students come ... </p>
</sec>
<sec sec-type="other1">
<title>Background</title>
<p>Differentiation has come ... </p>
<p>The pedagogical theory that ... </p>
<list id="L2" list-type="order"><list-item>Understand and be able to ... </list-item></list>
<p>At the university level, ... </p>
</sec>
<sec sec-type="other2">
<title>BRAIN Based Learning Environments</title>
<p>Clearly the most important role ...</p>
<p>Lets take a moment to ... </p>
</sec>
<sec sec-type="other4">
<title>Recognizing and Honoring Diversity</title>
<p>In a brain based classroom, ... </p>
<p>Content is what students are ...</p>
<list id="L3" list-type="order"><list-item>What do I want my ...</list-item></list>
<p>Process is the ... </p>
<p>Products are the way ...</p>
</sec>
</body>
</article>
xslt ================================================================
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="GetBodySections">
<xsl:for-each select="/article/body/sec">
<xsl:element name="section">
<!-- I dont know what to use in the for-each select -->
<xsl:for-each select=".">
<!-- once I have all the children of <sec> I will do xsl:choose and xsl:when to out put the para, title, or list the way I want -->
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Once I am on the sec node, how do I get all the children nodes? TIA.
Following are the source document fragments and the xslt fragment.
Source ========================================================
<?xml version="1.0" encoding="UTF-8"?>
<article>
<body>
<sec sec-type="intro">
<title>Introduction</title>
<p>Students come ... </p>
</sec>
<sec sec-type="other1">
<title>Background</title>
<p>Differentiation has come ... </p>
<p>The pedagogical theory that ... </p>
<list id="L2" list-type="order"><list-item>Understand and be able to ... </list-item></list>
<p>At the university level, ... </p>
</sec>
<sec sec-type="other2">
<title>BRAIN Based Learning Environments</title>
<p>Clearly the most important role ...</p>
<p>Lets take a moment to ... </p>
</sec>
<sec sec-type="other4">
<title>Recognizing and Honoring Diversity</title>
<p>In a brain based classroom, ... </p>
<p>Content is what students are ...</p>
<list id="L3" list-type="order"><list-item>What do I want my ...</list-item></list>
<p>Process is the ... </p>
<p>Products are the way ...</p>
</sec>
</body>
</article>
xslt ================================================================
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="GetBodySections">
<xsl:for-each select="/article/body/sec">
<xsl:element name="section">
<!-- I dont know what to use in the for-each select -->
<xsl:for-each select=".">
<!-- once I have all the children of <sec> I will do xsl:choose and xsl:when to out put the para, title, or list the way I want -->
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>