I have a list of FAQ's in an XML doc (see example below), and the tags within the "answer" node use <p>, <ol> and other standard tags. I want to use an XSLT stylesheet to convert these child nodes to liternal HTML tags after an XHTML transformation.
So here's an example XML doc:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<faq>
<question>This is where the question would be placed?</question>
<answer>
<p>This is where the answer would be placed:</p>
<ol>
<li>This would be the first point.</li>
<li>This would be the second point.</li>
<li>This would be the third point.</li>
<p>This is where a sub sentence would be placed.</p>
</answer>
</faq>
...and this is the XSLT stylesheet that I created to display these tags literally in the transformation to XHTML:
Code:
<xsl:template match="answer">
<xsl:for-each-group select="p" group-by="p">
<p><xsl:value-of select="current-grouping-key()"/></p>
</xsl:for-each-group>
<xsl:for-each-group select="em" group-by="p">
<em><xsl:value-of select="current-grouping-key()"/></em>
</xsl:for-each-group>
<xsl:for-each-group select="u" group-by="p">
[u]<xsl:value-of select="current-grouping-key()"/></u>
</xsl:for-each-group>
<xsl:for-each-group select="ol" group-by="p">
<ol><xsl:value-of select="current-grouping-key()"/></ol>
</xsl:for-each-group>
<xsl:for-each-group select="ul" group-by="p">
[list]<xsl:value-of select="current-grouping-key()"/></ul>
</xsl:for-each-group>
<xsl:for-each-group select="li" group-by="p">
<li><xsl:value-of select="current-grouping-key()"/></li>
</xsl:for-each-group>
</xsl:template>
But I keep receiving this error message:
System.Runtime.InteropServices.COMException: Keyword xsl:for-each-group may not be used here.
So I reviewed several online resources on XSLT Grouping, including
http://www.xml.com/lpt/a/2003/11/05/tr.html and
http://www.w3.org/TR/xslt20/#grouping-examples. I'm following the rules that were set in the examples included in these examples, but I'm still getting that message.
I even copied & pasted this example directly from the xml.com site:
XML:
Code:
<html><body>
<h1>Loomings</h1>
<p>par 1</p>
<p>par 2</p>
<p>par 3</p>
<h1>The Whiteness of the Whale</h1>
<p>par 4</p>
<p>par 5</p>
<p>par 6</p>
</body>
</html>
XSLT:
Code:
<xsl:template match="body">
<body>
<xsl:for-each-group select="*" group-starting-with="h1">
<chapter>
<xsl:for-each select="current-group()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:for-each>
</chapter>
</xsl:for-each-group>
</body>
</xsl:template>
Resulting XHTML:
[code]<html>
<body>
<chapter>
<h1>Loomings</h1>
<p>par 1</p>
<p>par 2</p>
<p>par 3</p>
</chapter>
<chapter>
<h1>The Whiteness of the Whale</h1>
<p>par 4</p>
<p>par 5</p>
<p>par 6</p>
</chapter>
</body>
</html>[code]
... but still received the error. So if anyone could let me know what I'm missing, it would be greatly appreciated. Thanks.
KWilliams