getting all the children of the context node
Here should go questions about transforming XML with XSLT and FOP.
getting all the children of the context node
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>
-
- Posts: 28
- Joined: Thu Mar 12, 2009 4:16 am
Re: getting all the children of the context node
Post by Rumplestiltzkin »
This should be very straight forward. Just do .
Code: Select all
<xsl:for-each select="*">
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: getting all the children of the context node
Post by sorin_ristache »
Hello,
Regards,
Sorin
As the above user Rumplestiltzkin recommended you can get the nodeset of all the child elements with the * expression. This is a basic XSLT question so you should first go through the examples of an XSLT tutorial.pschuller wrote:<!-- 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>
Regards,
Sorin
Re: getting all the children of the context node
Thanks for your replies but they were not helpful. - except to tell me that I had to figure it out for myself
I had already worked with select=".", and many other options. select="." gives me the entire <sec> node, which is the context node. I need to cycle through the children of <sec>.
For the benefit of others: <xsl:for-each select="child::*"> works. That got me each of the kids of <sec> and in then I am able to handle each one accordingly whether it is a <title>, <p>, or <list>.
The other thing I learned is that the intellisense in oXygen is not complete. When you type child:: it offers a list of about 6 items but it does not offer * If it had I might have been able to get this w o ever posting here. Anyway, thanks again.
I had already worked with select=".", and many other options. select="." gives me the entire <sec> node, which is the context node. I need to cycle through the children of <sec>.
For the benefit of others: <xsl:for-each select="child::*"> works. That got me each of the kids of <sec> and in then I am able to handle each one accordingly whether it is a <title>, <p>, or <list>.
The other thing I learned is that the intellisense in oXygen is not complete. When you type child:: it offers a list of about 6 items but it does not offer * If it had I might have been able to get this w o ever posting here. Anyway, thanks again.
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service