|
Subject:
|
Xsl: strip-space elements; and 'group-adjacent'
|
|
Posted By:
|
ROCXY
|
Post Date:
|
1/4/2006 11:46:26 PM
|
Hi All,
I have an XML,
<?xml version="1.0"?> <artbody> <section id="s1">
<quest>What's your name?</quest> <quest>What's your name?</quest> <answer>Rocxky</answer> <answer>Rocxky</answer> </section> </artbody>
Used XSL. --------- <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/> <xsl:template match="*"> <xsl:copy> <xsl:for-each-group select="child::node()" group-adjacent="self::quest or self::answer"> <xsl:choose> <xsl:when test="current-grouping-key()"> <QandA> <xsl:apply-templates select="current-group()" /> </QandA> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:copy> </xsl:template> </xsl:stylesheet>
Observed Output --------------- <?xml version="1.0" encoding="UTF-8"?> <artbody> <section> <QandA> <quest>What's you name?</quest> <quest>What's you name?</quest> <answer>Rocxky</answer> <answer>Rocxky</answer> </QandA> </section> </artbody>
As you see <xsl:strip-space elements="*"/> the attribute value "s1" of <section id="s1"> to <section>.
Kindly suggest us how to convert section with attributes as it is to the target XML.
Thanks & Regards, -ROCXKY
|
|
Reply By:
|
mhkay
|
Reply Date:
|
1/5/2006 4:24:39 AM
|
After
<xsl:copy>
add
<xsl:copy-of select="@*"/>
if you want to copy the attributes unchanged.
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
Reply By:
|
ROCXY
|
Reply Date:
|
1/5/2006 10:29:45 PM
|
Thanks for the reply.
-ROCXY
|