[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Re: Grouping by attribute

Subject: Re: Re: Grouping by attribute
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Wed, 21 Oct 2009 17:22:37 +0200
Re:  Re: Grouping by attribute
Lajos Joo wrote:
I am using xmlspy for testing with the built in xslt engine which said that it is not a node item.
And in java:
Exception dropped during XSLT transformation: net.sf.saxon.trans.DynamicError: Required item type of second operand of 'intersect' is node(); supplied value has item type xs:string

I can see that happening when your complete XML has more than those 'par' element and that way the template is applied without passing in a value for the parameter.


In that case it might be better to introduce a mode to process those descendants of 'par' elements e.g.

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="xsd">

<xsl:output indent="yes"/>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@*, node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="node()" mode="m1">
    <xsl:param name="cn"/>
    <xsl:if test="descendant-or-self::node() intersect $cn">
      <xsl:copy>
        <xsl:apply-templates select="@*"/>
        <xsl:apply-templates select="node()" mode="m1">
          <xsl:with-param name="cn" select="$cn"/>
        </xsl:apply-templates>
      </xsl:copy>
    </xsl:if>
  </xsl:template>

<xsl:template match="par">
<xsl:variable name="p" as="element()" select="."/>
<xsl:for-each-group select="descendant::node()" group-ending-with="linebreak">
<xsl:variable name="lb" as="element()?" select="current-group()[self::linebreak]"/>
<par>
<xsl:apply-templates select="$p/@*"/>
<xsl:apply-templates select="$p/node()[descendant-or-self::node() intersect (current-group() except $lb)]" mode="m1">
<xsl:with-param name="cn" select="current-group() except $lb"/>
</xsl:apply-templates>
</par>
</xsl:for-each-group>
</xsl:template>


</xsl:stylesheet>


--


	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.