Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Node Grouping

From: "Yan Leshinsky" <yanl@------.---------.--->
To: NULL
Date: 6/3/2004 8:33:00 PM
This is a multi-part message in MIME format.

------=_NextPart_000_002E_01C449A9.FF43F180
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

It is possible abter all :)
Following is the simplified example that should give you an idea:

-------------------------------------------------------------------------=
-------

XSL:
<xsl:stylesheet version=3D"1.0"
 xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
 xmlns:msxsl=3D"urn:schemas-microsoft-com:xslt"
 exclude-result-prefixes=3D"msxsl">


<xsl:template match=3D"/root">
<root>
 <xsl:variable name=3D"trio">
  <xsl:call-template name=3D"doA">
   <xsl:with-param name=3D"this" select=3D"a[1]" />
   <xsl:with-param name=3D"bCount" select=3D"0" />
  </xsl:call-template>
 </xsl:variable>
 <xsl:for-each select=3D"msxsl:node-set($trio)//trio">
  <set>
   <xsl:copy-of select=3D"a"/>
  </set>
 </xsl:for-each>
</root>
</xsl:template>

<xsl:template name=3D"doA">
 <xsl:param name=3D"this" />
 <xsl:param name=3D"bCount" />
 <xsl:if test=3D"$this">
  <xsl:choose>
   <xsl:when test=3D"count($this/b) &lt; $bCount">
    <xsl:copy-of select=3D"$this" />
    <xsl:call-template name=3D"doA">
     <xsl:with-param name=3D"this" =
select=3D"$this/following-sibling::a[1]" />
     <xsl:with-param name=3D"bCount" select=3D"$bCount - count($this/b)" =


/>
    </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
    <trio>
     <xsl:call-template name=3D"doA">
      <xsl:with-param name=3D"this" select=3D"$this" />
      <xsl:with-param name=3D"bCount" select=3D"4" />
     </xsl:call-template>
    </trio>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:if>
</xsl:template>
 =20
</xsl:stylesheet>

-------------------------------------------------------------------------=
-------
XML:
<root>
<a>
 <b>1</b>
 <b>2</b>
</a>
<a>
 <b>3</b>
 <b>4</b>
</a>
<a>
 <b>5</b>
 <b>6</b>
</a>
<a>
 <b>7</b>
</a>
<a>
 <b>8</b>
</a>
</root>

-------------------------------------------------------------------------=
-------
Output:
<root>
    <set>
        <a>
            <b>1</b>
            <b>2</b>
        </a>
    </set>
    <set>
        <a>
            <b>3</b>
            <b>4</b>
        </a>
    </set>
    <set>
        <a>
            <b>5</b>
            <b>6</b>
        </a>
        <a>
            <b>7</b>
        </a>
    </set>
    <set>
        <a>
            <b>8</b>
        </a>
    </set>
</root>

-------------------------------------------------------------------------=
-------


You just need to change a to Products/ProductsItem and b to =
Identifiers/Identifier
Have fun!
------=_NextPart_000_002E_01C449A9.FF43F180
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2096" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>It is possible abter all =
:)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Following is the simplified example =
that should=20
give you an idea:</FONT></DIV><FONT size=3D2>
<DIV><FONT face=3DArial>
<HR>
</FONT></DIV>
<DIV><FONT face=3DArial>XSL:</FONT></DIV>
<DIV></FONT><FONT face=3DArial size=3D2>&lt;xsl:stylesheet=20
version=3D"1.0"<BR>&nbsp;xmlns:xsl=3D"</FONT><A=20
href=3D"http://www.w3.org/1999/XSL/Transform"><FONT face=3DArial=20
size=3D2>http://www.w3.org/1999/XSL/Transform</FONT></A><FONT =
face=3DArial=20
size=3D2>"<BR>&nbsp;xmlns:msxsl=3D"urn:schemas-microsoft-com:xslt"<BR>&nb=
sp;exclude-result-prefixes=3D"msxsl"&gt;</FONT></DIV>
<DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT><FONT size=3D2></FONT><BR><FONT face=3DArial=20
size=3D2>&lt;xsl:template=20
match=3D"/root"&gt;<BR>&lt;root&gt;<BR>&nbsp;&lt;xsl:variable=20
name=3D"trio"&gt;<BR>&nbsp;&nbsp;&lt;xsl:call-template=20
name=3D"doA"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;xsl:with-param name=3D"this" =
select=3D"a[1]"=20
/&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;xsl:with-param name=3D"bCount" =
select=3D"0"=20
/&gt;<BR>&nbsp;&nbsp;&lt;/xsl:call-template&gt;<BR>&nbsp;&lt;/xsl:variabl=
e&gt;<BR>&nbsp;&lt;xsl:for-each=20
select=3D"msxsl:node-set($trio)//trio"&gt;<BR>&nbsp;&nbsp;&lt;set&gt;<BR>=
&nbsp;&nbsp;&nbsp;&lt;xsl:copy-of=20
select=3D"a"/&gt;<BR>&nbsp;&nbsp;&lt;/set&gt;<BR>&nbsp;&lt;/xsl:for-each&=
gt;<BR>&lt;/root&gt;<BR>&lt;/xsl:template&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&lt;xsl:template=20
name=3D"doA"&gt;<BR>&nbsp;&lt;xsl:param name=3D"this" =
/&gt;<BR>&nbsp;&lt;xsl:param=20
name=3D"bCount" /&gt;<BR>&nbsp;&lt;xsl:if=20
test=3D"$this"&gt;<BR>&nbsp;&nbsp;&lt;xsl:choose&gt;<BR>&nbsp;&nbsp;&nbsp=
;&lt;xsl:when=20
test=3D"count($this/b) &amp;lt;=20
$bCount"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:copy-of select=3D"$this" =

/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:call-template=20
name=3D"doA"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:with-param =
name=3D"this"=20
select=3D"$this/following-sibling::a[1]"=20
/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:with-param =
name=3D"bCount"=20
select=3D"$bCount - count($this/b)" </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/xsl:call-template&gt;<BR>&=
nbsp;&nbsp;&nbsp;&lt;/xsl:when&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;xsl:otherwise=
&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;trio&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&lt;xsl:call-template=20
name=3D"doA"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:with-para=
m=20
name=3D"this" select=3D"$this"=20
/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xsl:with-param =
name=3D"bCount"=20
select=3D"4"=20
/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/xsl:call-template&gt;<BR>&nbs=
p;&nbsp;&nbsp;&nbsp;&lt;/trio&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;/xsl:otherwise=
&gt;<BR>&nbsp;&nbsp;&lt;/xsl:choose&gt;<BR>&nbsp;&lt;/xsl:if&gt;<BR>&lt;/=
xsl:template&gt;<BR>&nbsp;&nbsp;<BR>&lt;/xsl:stylesheet&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>
<HR>
XML:</FONT></DIV>
<DIV>
<DIV><FONT face=3DArial><FONT=20
size=3D2>&lt;root&gt;<BR>&lt;a&gt;<BR>&nbsp;&lt;b&gt;1&lt;/b&gt;<BR>&nbsp=
;&lt;b&gt;2&lt;/b&gt;<BR>&lt;/a&gt;<BR>&lt;a&gt;<BR>&nbsp;&lt;b&gt;3&lt;/=
b&gt;<BR>&nbsp;&lt;b&gt;4&lt;/b&gt;<BR>&lt;/a&gt;<BR>&lt;a&gt;<BR>&nbsp;&=
lt;b&gt;5&lt;/b&gt;<BR>&nbsp;&lt;b&gt;6&lt;/b&gt;<BR>&lt;/a&gt;<BR>&lt;a&=
gt;<BR>&nbsp;&lt;b&gt;7&lt;/b&gt;<BR>&lt;/a&gt;<BR>&lt;a&gt;<BR>&nbsp;&lt=
;b&gt;8&lt;/b&gt;<BR>&lt;/a&gt;<BR>&lt;/root&gt;<BR></FONT><FONT=20
size=3D2>
<HR>
Output:</FONT></FONT></DIV>
<DIV><FONT size=3D2></FONT><FONT face=3DArial =
size=3D2>&lt;root&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
&lt;set&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;a&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &lt;b&gt;1&lt;/b&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &lt;b&gt;2&lt;/b&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;/a&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
&lt;/set&gt;</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&lt;set&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;a&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &lt;b&gt;3&lt;/b&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &lt;b&gt;4&lt;/b&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;/a&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
&lt;/set&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
&lt;set&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;a&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &lt;b&gt;5&lt;/b&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &lt;b&gt;6&lt;/b&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;/a&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;a&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &lt;b&gt;7&lt;/b&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;/a&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
&lt;/set&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
&lt;set&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;a&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &lt;b&gt;8&lt;/b&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&lt;/a&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
&lt;/set&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&lt;/root&gt;<BR>
<HR>
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><FONT size=3D3>
<DIV><FONT face=3DArial size=3D2>You just need to change a to =
Products/ProductsItem=20
and b to Identifiers/Identifier</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Have=20
fun!</FONT></DIV></FONT></DIV></FONT></DIV></DIV></BODY></HTML>

------=_NextPart_000_002E_01C449A9.FF43F180--



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent