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

Re: grouping + global variable (?) (was re: regexs, g

Subject: Re: grouping + global variable (?) (was re: regexs, grouping (?) and XSLT2?)
From: Bruce D'Arcus <bdarcus@xxxxxxxxxxxxx>
Date: Fri, 13 Aug 2004 12:15:21 -0400
xsl global variable
On Aug 12, 2004, at 6:13 PM, Michael Kay wrote:

How am I generating this "copy", in other words?  Should I, for
example, be using the new temporary tree functionality? Within the
context of a variable?  Something else?

Basically:


<xsl:template match="/">
  <xsl:variable name="temp">
    <xsl:apply-templates select="." mode="phase-1"
  </xsl:variable>
  <xsl:apply-templates select="$temp" mode="phase-2"/>
</xsl:template>

So you're doing a two-phase transformation, with $temp holding the
output of
the first phase, which acts as the input to the second phase. You
don't have
to use different modes, but it makes things clearer.

Since the bibliography is only part of the document, and in a separate namespace, I decided to create a virtual copy of the mods:modsCollection element in the phase-1 mode, and then to apply-templates on that in the default mode; like so:

<xsl:template match="mods:modsCollection">
  <xsl:variable name="temp">
    <xsl:apply-templates select="." mode="phase-1"/>
  </xsl:variable>
  <xsl:apply-templates select="$temp"/>
</xsl:template>

<xsl:template match="mods:modsCollection">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates mode="phase-1"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="mods:mods" mode="phase-1">
  <xsl:copy>
    <xsl:copy-of select="*|@*"/>
    <xsl:variable name="bibref" select="mods:mods" />
    <xsl:for-each-group select="$bibref"
group-by="mods:grouping-key(.)">
      <xsl:sort select="current-grouping-key()"/>
      <xsl:for-each-group select="current-group()"

group-by="xs:integer(substring(mods:originInfo/mods:dateIssued,1,4))">
	<xsl:sort select="current-grouping-key()" />
	<xsl:variable name="year" as="xs:integer"
		select="current-grouping-key()"/>
	<xsl:variable name="first" as="xs:boolean" select="position() = 1" />
	<xsl:for-each select="current-group()">
	  <xsl:attribute name="id">
	    <xsl:value-of select="@ID"/>
	  </xsl:attribute>
	  <key type="creator">
	    <xsl:value-of select="$creator-before"/>
	    <xsl:choose>
	      <xsl:when test="$first and position()=1">
		<xsl:apply-templates select="." mode="names"/>
		<xsl:text> </xsl:text>
	      </xsl:when>
	      <xsl:otherwise>.</xsl:otherwise>
	    </xsl:choose>
	    <xsl:value-of select="$creator-after"/>
	  </key>
	  <key type="year">
	    <xsl:value-of select="$year" />
	    <xsl:if test="last() > 1">
	      <xsl:number value="position()" format="a"/>
	    </xsl:if>
	  </key>
	</xsl:for-each>
      </xsl:for-each-group>
    </xsl:for-each-group>
  </xsl:copy>
</xsl:template>

My problem is I can't access the generated year, which should be of the
form:

<mods:key type="year">1999a</mods:key>.

I have a feeling this means something's gone wrong with this
intermediate step, as if I apply-templates to "mods:key" within the
default mode of mods:modsCollection, I get no output.  Everything but
the year gets rendered correctly.

Is there something obviously wrong with the above?  Maybe the way I've
generated the copy?  I thought it might be a namespace problem, but
that's not it.

Bruce

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.