|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] iterate through nodes and determine output by node typ
I'd like to test all child elements of a body tag and wrap any text nodes (that
can contain child elements itself)in a p tag and <apply-templates /> to any
element nodes.
Using XSLT 1.1
Sample input
<body>
blah blah blah <strong>blah blah blah</strong>
<p>a paragraph...</p>
<p>a paragraph...</p>
<table>
<tr>
<td>content goes here</td>
<td>content goes here</td>
<tr>
</table>
</body>
sample output
<body>
<p>blah blah blah <strong>blah blah blah</strong></p>
<p>a paragraph...</p>
<p>a paragraph...</p>
<table>
<tr>
<td>content goes here</td>
<td>content goes here</td>
<tr>
</table>
</body>
Sample code
<xsl:template match="//body">
<body>
<xsl:for-each select="child::*">
<xsl:choose>
<xsl:when test="text()">
<p id="{generate-id()}"><xsl:apply-templates /></p>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</body>
</xsl:template>
Thanks
Marijan (Mario) Madunic
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






