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

Re: XSLT2, collection(), and xsl:key

Subject: Re: XSLT2, collection(), and xsl:key
From: "James Cummings" <cummings.james@xxxxxxxxx>
Date: Wed, 6 Feb 2008 12:21:33 +0000
Re:  XSLT2
On Feb 1, 2008 6:39 PM, Michael Kay <mike@xxxxxxxxxxxx> wrote:
> OK, I misunderstood. I thought that's what you meant by doing it manually,
> and that that wasn't what you wanted to do.
>
> To make it data-driven like this, you get rid of the outer
> xsl:for-each-group and replace it with an <xsl:for-each select="table">, and
> then you do something like
>
> <xsl:variable name="table" select="."/>
> <xsl:variable name="pop"
> select="collection('...')//*[name()=$table/@element[@*[name()=$table/@att]]]
> "/>
>
> and then
>
> <xsl:variable name="types"
> select="distinct-values($pop/@*[name()=$table/@att)"/>

Just for posterity (because I'm bound to forget...), to check I'm
doing it right if anyone cares to comment what I ended up doing was
something along the lines of:

<xsl:variable name="docs"  select="collection('../../working/xml/files.xml')"/>

<xsl:variable name="tables">
  <table element="placeName" att="type"/>
  <table element="persName" att="type"/>
  <!-- And many more etc -->
</xsl:variable>

<xsl:for-each select="$tables/tei:table">
  <xsl:variable name="table" select="."/>
  <xsl:variable name="pop"
  select="$docs//*[name()=$table/@element][@*[name()=$table/@att]]"/>
  <xsl:variable name="types"
  select="distinct-values($pop/@*[name()=$table/@att])"/>
  <table>
  <tr>
    <td>document</td>
    <xsl:variable name="types"
      select="distinct-values($pop/@*[name()=$table/@att])"/>
    <xsl:for-each select="$types">
      <td><xsl:value-of select="."/></td>
    </xsl:for-each>
  </tr>
  <xsl:for-each-group select="$pop"
    group-by="ancestor-or-self::tei:text">
    <tr>
      <td><xsl:value-of
        select="ancestor-or-self::tei:text//tei:date[1]/substring-before(@when,
'-')"/></td>
      <xsl:for-each select="$types">
        <td><xsl:value-of
          select="count(current-group()[@type=current()])"/></td>
      </xsl:for-each>
    </tr>
    </xsl:for-each-group>
</table>
  </xsl:for-each>

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-2007 All Rights Reserved.