Subject: RE: variables, grouping, and result-documents
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 18 Dec 2007 22:49:14 -0000
|
You could replace
<xsl:variable name="stateName" select="current-group()/@state"/>
by
<xsl:variable name="stateName" select="current-group()[1]/@state"/>
or more simply by
<xsl:variable name="stateName" select="current-grouping-key()"/>
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: Terry Ofner [mailto:tofner@xxxxxxxxxxx]
> Sent: 18 December 2007 21:28
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: variables, grouping, and result-documents
>
> I am having trouble naming result documents. Here is a style
> sheet that included two-level grouping and a result-document
> statement.
>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:fo="http://www.w3.org/1999/XSL/Format">
> <xsl:output method="xml" indent="no"/>
>
> <!--State Standards file-->
> <xsl:variable name="StateFile"
> select="document('stateCodes.xml')" /> <xsl:key
> name="standard" match="state" use="@abbr" />
>
> <!--Lesson Name file-->
> <xsl:variable name="lessonFile"
> select="document('Grade4Skills.tab')" /> <xsl:key
> name="lessonName_by_num" match="skill" use="@num" />
>
>
> <!--start grouping by states and naming result-documents-->
>
> <xsl:template match="/">
> <xsl:for-each-group select="/Root/Story/State_Standard"
> group- by="@state">
> <xsl:variable name="stateName" select="current-group()/@state"/>
> <xsl:result-document href="{$stateName}.fo">
>
> <!--Define FO page layouts and Place State Standard at top of
> table--> <!--fo:master page formatting cut out:-->
>
> <fo:static-content flow-name="headerRest">
> <fo:block text-align="end"
> font-size="10pt"
> font-family="serif"
> line-height="14pt" >
> Reading Express Level D / <xsl:variable name="LocalState"
> select="$stateName" />
> <xsl:for-each select="$StateFile">
> <xsl:value-of select="key('standard', $LocalState)" />
> </xsl:for-each> Correlation - p. <fo:page-number/>
> </fo:block>
> </fo:static-content>
>
> <fo:flow flow-name="xsl-region-body"> <fo:block
> font-size="16pt"
> font-family="sans-serif"
> font-weight="bold"
> line-height="24pt"
> space-after.optimum="15pt"
> background-color="gray"
> color="white"
> text-align="center">
> <xsl:variable name="LocalState" select="$stateName" />
> <xsl:for-each select="$StateFile"> <xsl:value-of
> select="key('standard', $LocalState)" /> </xsl:for-each>
> </fo:block>
> <fo:block font-size="11pt"
> font-family="serif"
> line-height="24pt"
> space-after.optimum="15pt"
> background-color="white"
> color="black"
> text-align="left">
> <xsl:variable name="LocalState" select="$stateName" />
> This chart correlates the <xsl:for-each
> select="$StateFile"><xsl:value-of select="key('standard',
> $LocalState)" /></xsl:for-each> to the lessons of Reading
> Express, Level D.
> </fo:block>
>
>
> <fo:table-body>
> <xsl:for-each-group select="current-group()/SS" group-by=".">
> <xsl:sort select="."/>
> <fo:table-row border-color="black" border-width="0.5pt"
> border-style="solid" keep-together.within-page="always">
>
> <fo:table-cell padding="4pt"
> keep-together.within- page="always">
> <fo:block text-align="left" font-size="11pt" font-
> family="serif" text-indent="-24pt" start-indent="24pt">
> <xsl:copy-of select="node()"/>
> </fo:block>
> </fo:table-cell>
> <xsl:variable name="skillNumber"
> select="current-group ()/../@skill"/>
> <xsl:for-each select="$lessonFile">
> <fo:table-cell padding="4pt" keep-
> together.within-page="always">
> <fo:block text-align="left" font-size="11pt"
> font- family="serif">
> <xsl:copy-of select="key('lessonName_by_num',
> $skillNumber)/child::node()" />
> </fo:block>
> </fo:table-cell>
> </xsl:for-each>
> </fo:table-row>
> </xsl:for-each-group>
> </fo:table-body>
> </fo:table>
>
> </fo:flow>
> </fo:page-sequence>
> </fo:root>
> </xsl:result-document>
> </xsl:for-each-group>
> </xsl:template>
> </xsl:stylesheet>
>
> The source xml contains multiple standards each for all 50
> states and DC.
>
> <?xml version="1.0"?>
> <Root>
> <Story>
> <State_Standard skill="01" state="AZ">
> <State>Arizona Standards</State>
> <SS>1.4.1 Use knowledge of root words and
> affixes to determine the meaning of unknown
> words.</SS>
> </State_Standard>
> </Story>
> <State_Standard skill="29" state="CA">
> <State>California Standards</State>
> <SS>2.1 Identify structural patterns found in
> informational text to strengthen
> comprehension.</SS>
> </State_Standard>
> </Story>
> </Root>
>
> The contents of the resulting documents look great. It is the
> resulting file names that are loopy. Here are the names of
> two of my resulting files:
>
> FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL
> FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL
> FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL FL.fo
>
> and
>
> CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA
> CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA
> CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA CA.fo
>
> It seems that I have this variable line in the wrong place:
>
> <xsl:variable name="stateName" select="current-group()/@state"/>
>
> Am I trying to do too much inside this one template?
> Do I need two templates?
>
> Thanks in advance,
>
> Terry Ofner
|