XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
jega kannanSubject: Grouping without disturbing other elements
Author: jega kannan
Date: 05 Jan 2006 02:08 AM
Input XML:
---------

<artbody>
<section>
<heading 1>xxxxxx</heading1>
<p>xxxxxx</p>
<p>xxxxxx</p>
<subsect>
<p>xxxxxx</p>
<quest>xxxxxx</quest>
<answer>xxxxxxx<answer>
<quest>xxxxxx</quest>
<answer>xxxxxxx<answer>
<quest>xxxxxx</quest>
<answer>xxxxxxx<answer>
<p>xxxxxx</p>
<stanza>xxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxx</stanza>

</subsect>
</section>

<section>
<heading 1>xxxxxx</heading1>
<p>xxxxxx</p>
<p>xxxxxx</p>
<stanza>xxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxx</stanza>
<p>xxxxxx</p>
<p>xxxxxx</p>
<p>xxxxxx</p>
</section>

</artbody>

========================================================================

Expected output XML:
-------------------

<artbody>

<section>
<heading 1>xxxxxx</heading1>
<p>xxxxxx</p>
<p>xxxxxx</p>
<subsect>
<p>xxxxxx</p>

<qanda>

<quest>xxxxxx</quest>
<answer>xxxxxxx<answer>
<quest>xxxxxx</quest>
<answer>xxxxxxx<answer>
<quest>xxxxxx</quest>
<answer>xxxxxxx<answer>

</qanda>

<p>xxxxxx</p>

<poem>

<stanza>xxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxx</stanza>

<poem>

</subsect>
</section>

<section>
<heading 1>xxxxxx</heading1>
<p>xxxxxx</p>
<p>xxxxxx</p>

<poem>

<stanza>xxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxx</stanza>

</poem>

<p>xxxxxx</p>
<p>xxxxxx</p>
<p>xxxxxx</p>


</section>

</artbody>

========================================================================
XSLT:
-----

<xsl:output method="xml"
indent="yes"
omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>


<xsl:template match="*">
<xsl:for-each select=".//*">

<xsl:choose>

<xsl:when test="descendant::*[self::quest]">

<xsl:copy>
<xsl:for-each-group select="child::node()" group-adjacent="self::quest or self::answer">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<quanta>
<xsl:copy-of select="current-group()"/>
</quanta>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:when>

<xsl:when test="descendant::*[self::stanza]">
<xsl:copy>
<xsl:for-each-group select="child::node()" group-adjacent="self::stanza or self::stanza">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<poem>
<xsl:copy-of select="current-group()"/>
</poem>
</xsl:when>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:when>



<xsl:otherwise>
<xsl:apply-templats select="current-group()"/>


</xsl:otherwise>


</xsl:choose>
</xsl:for-each>


</xsl:template>


</xsl:stylesheet>
========================================================================
Generated output using above xslt:
---------------------------------


<artbody/>
<section/>

<subsect>
<quanta>
<quest>xxxxxxxxxxxxxxxx</quest>
<answer>xxxxxxxxxxx</answer>
<quest>xxxxxxxxxx</quest>
<answer>xxxxxxxxxxx</answer>
<quest>xxxxxxxxxx</quest>
<answer>xxxxxxxxxxxx</answer>
<quest>xxxxxxxxxxx</quest>
<answer>xxxxxxxxxxxxx</answer>
</quanta>

<poem>
<stanza>xxxxxxxxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxxxxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxxxxxxxxxx</stanza>
</poem>

<subsect>
<poem>
<stanza>xxxxxxxxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxxxxxxxxxxxxxxx</stanza>
<stanza>xxxxxxxxxxxxxxxxxxxxx</stanza>
</poem>
</subsect>

========================================================================
Questions:
---------

1. Why i didn't get all other elements? I have tried last 14 hrs to bring other elements dynamically to output xml. Please help me.











Posttop
Tony LavinioSubject: Grouping without disturbing other elements
Author: Tony Lavinio
Date: 05 Jan 2006 11:42 AM
It's difficult to figure out what you are doing. First, the sample
documents you've provided aren't valid XML. But even fixing that,
all the xxxxx's are confusing. Which source values are supposed to
end up in which target locations?

If this is a general grouping question and not a Stylus Studio question,
you might try asking it on the xsl-list mailing list. See
http://www.stylusstudio.com/xsllist/ and use the sign-on box on the
right.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.