Subject: Re: [xsl] grouping + global variable (?) (was re: regexs, From: Bruce D'Arcus <bdarcus@xxxxxxxxxxxxx> Date: Fri, 13 Aug 2004 18:30:12 -0400 |
Okay, but why are both these templates matching the same elements with the same priority, in no mode? They are in conflict and your processor will only use one of them (or throw an error).
<?xml version="1.0" encoding="utf-8"?> <article xmlns="http://docbook.org/docbook-ng"> <info> <title>Test</title> </info> <section> <info> <title>Introduction</title> </info> <para>Some citations: <citation><biblioref linkend="one"/><biblioref linkend="two"/><biblioref linkend="three"/></citation></para> </section> <bibliography> <modsCollection xmlns="http://www.loc.gov/mods/v3"> <mods ID="one"> <name type="personal"> <namePart type="given">John</namePart> <namePart type="family">Doe</namePart> <role> <roleTerm type="text">author</roleTerm> </role> </name> <titleInfo> <title>Some Title</title> </titleInfo> <originInfo> <dateIssued>1999</dateIssued> </originInfo> </mods> <mods ID="two"> <name type="personal"> <namePart type="given">John</namePart> <namePart type="family">Doe</namePart> <role> <roleTerm type="text">author</roleTerm> </role> </name> <titleInfo> <title>Another Title</title> </titleInfo> <originInfo> <dateIssued>1999</dateIssued> </originInfo> </mods> <mods ID="three"> <name type="personal"> <namePart type="given">John</namePart> <namePart type="family">Doe</namePart> <role> <roleTerm type="text">author</roleTerm> </role> </name> <name type="personal"> <namePart type="given">Jane</namePart> <namePart type="family">Jones</namePart> <role> <roleTerm type="text">author</roleTerm> </role> </name> <titleInfo> <title>Some Title</title> </titleInfo> <originInfo> <dateIssued>1999</dateIssued> </originInfo> </mods> </modsCollection> </bibliography> </article>
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdt="http://www.w3.org/2003/11/xpath-datatypes" xmlns:str="http://example.org/xslt/functions" xmlns:db="http://docbook.org/docbook-ng" xmlns:mods="http://www.loc.gov/mods/v3" xmlns:bib="http://www.example.org/bib" xmlns="http://www.loc.gov/mods/v3" exclude-result-prefixes="xs xdt mods str db bib" version="2.0">
<xsl:output method="xml" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/>
<xsl:template match="/"> <xsl:apply-templates select="//mods:modsCollection"/> </xsl:template>
<xsl:function name="bib:grouping-key" as="xs:string"> <xsl:param name="bibref" as="element(mods:mods)" /> <xsl:value-of separator=";"> <xsl:for-each select="$bibref/mods:name"> <xsl:value-of select="string-join((mods:namePart[@type = 'family'], mods:namePart[@type = 'given']), ',')" /> </xsl:for-each> </xsl:value-of> </xsl:function>
<xsl:template match="mods:modsCollection"> <xsl:variable name="temp"> <xsl:apply-templates select="." mode="phase-1"/> </xsl:variable> <xsl:apply-templates select="$temp" mode="phase-2"/> </xsl:template>
<xsl:template match="mods:modsCollection" mode="phase-1"> <xsl:copy> <xsl:variable name="bibref" select="mods:mods" /> <xsl:for-each-group select="$bibref" group-by="bib:grouping-key(.)"> <xsl:sort select="current-grouping-key()"/> <xsl:for-each-group select="current-group()" group-by="xs:integer(substring(mods:originInfo/mods:dateIssued| mods:relatedItem/mods:part/mods:date,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()"> <mods ID="{@ID}"> <xsl:if test="last() > 1"> <key type="year-suffix"> <xsl:number value="position()" format="a"/> </key> </xsl:if> <xsl:copy-of select="*"/> </mods> </xsl:for-each> </xsl:for-each-group> </xsl:for-each-group> </xsl:copy> </xsl:template>
<xsl:template match="mods:modsCollection" mode="phase-2"> <div class="bibliography"> <xsl:apply-templates select="mods:mods"/> </div> </xsl:template>
<xsl:template match="mods:mods"> <div class="record" id="{@ID}"> <xsl:apply-templates select="mods:titleInfo[not(@type)]"/> <xsl:apply-templates select="mods:key"/> </div> </xsl:template>
<xsl:template match="mods:titleInfo[not(@type)]"> <h3> <xsl:apply-templates select="mods:title"/> <xsl:apply-templates select="mods:subTitle"/> </h3> </xsl:template>
<xsl:template match="mods:title"> <xsl:apply-templates/> </xsl:template>
<xsl:template match="mods:subTitle"> <xsl:text>: </xsl:text> <xsl:apply-templates/> </xsl:template>
<xsl:template match="mods:key"> <p> <xsl:text>has suffix of </xsl:text> <xsl:apply-templates/> </p> </xsl:template>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] grouping + global variabl, Wendell Piez | Thread | Re: [xsl] grouping + global variabl, Wendell Piez |
Re: [xsl] Need exactly 23 rows of o, Clay Leeds | Date | Re: [xsl] grouping + global variabl, Wendell Piez |
Month |