xsl-list
[Top] [All Lists]

RE: [xsl] losing element tags during copy-of

2007-12-11 15:41:50
The value of current-grouping-key() is always an atomic value, never a node.
When you do group-by=".", the node is atomized to evaluate the grouping key
(which will be of type xs:untypedAtomic - for practical purposes, a string).
You can output the first item in the group using <xsl:copy-of select="."/>
which will give you the element structure. Other items might have been added
to the same group even though their internal markup is different, because
it's ignored in calculating the grouping key.

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: Terry Ofner [mailto:tofner(_at_)comcast(_dot_)net] 
Sent: 11 December 2007 21:57
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] losing element tags during copy-of 

Original xml is in the following format. Note the <i> 
elements in the <SS> elements.

<Root>
   <Story>
     <State_Standard skill="01" state="GA">
       <State>Georgia Standards</State>
       <SS>ELA3R2e The student identifies and infers meaning 
from common root words, common prefixes (e.g.,
      <i>un-, re-, dis-, in-</i>), and common suffixes (e.g., 
<i>-tion, - ous, -ly</i>).</SS>
     </State_Standard>
   </Story>
   <Story>
     <State_Standard skill="02" state="GA">
       <State>Georgia Standards</State>
       <SS>ELA3R2e The student identifies and infers meaning 
from common root words, common prefixes (e.g.,
       <i>un-, re-, dis-, in-</i>), and common suffixes 
(e.g., <i>- tion, -ous, -ly</i>).</SS>
     </State_Standard>
   </Story>
  . . .
</Root>

I am processing this using the following 2.0 stylsheet (Saxon8):

<xsl:stylesheet version="2.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
      xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/";>
<xsl:output method="xml" indent="no"/>
<xsl:strip-space elements= "*" />

<!--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('Grade3Skills.tab')" /> <xsl:key 
name="lessonName_by_num" match="skill" use="@num" />

<!--Place State Standard info at top page-->

<xsl:template match="/">
<Root><Title>
      <xsl:variable name="LocalState" select="//@state" />
      <xsl:for-each select="$StateFile">
      <xsl:value-of select="key('standard', $LocalState)" />
      </xsl:for-each>
      </Title><xsl:text>&#10;</xsl:text>
<xsl:variable name="LocalState" select="//@state" />
      <Description>This chart correlates the <xsl:for-each 
select="$StateFile"><xsl:value-of select="key('standard', 
$LocalState)" /></xsl:for-each> to the lessons of <b>xxxx, Level C.</ 
b></Description><xsl:text>&#10;</xsl:text>

<!--Insert Adobe InDesign Table Header--> <Table 
xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/";  
aid:table="table" aid:trows="33" 
aid:tcols="2"><xsl:text>&#10;</ xsl:text>

   <Cell aid:table="cell" aid:theader="" aid:crows="1" aid:ccols="1"  
aid:ccolwidth="342.5">Standard</Cell><xsl:text>&#10;</xsl:text>

   <Cell aid:table="cell" aid:theader="" aid:crows="1" aid:ccols="1"  
aid:ccolwidth="197">Lesson(s)</Cell><xsl:text>&#10;</xsl:text>

<!--Grouping xml for first column of table-->
   <xsl:for-each-group select="//SS" group-by=".">
   <xsl:sort select="."/>
     <Cell aid:table="cell" aid:crows="1" aid:ccols="1"  
aid:ccolwidth="342.5">

<xsl:copy-of select="current-grouping-key()"/></Cell><xsl:text>&#9;</
xsl:text>

!--Add lessons info for second column of table-->
   <xsl:variable name="skillNumber" 
select="current-group()/../@skill"/>
     <xsl:for-each select="$lessonFile">
     <Cell aid:table="cell" aid:crows="1" aid:ccols="1"  
aid:ccolwidth="197.">
<xsl:value-of select="key('lessonName_by_num', $skillNumber)" /></ 
Cell><xsl:text>&#10;</xsl:text>
     </xsl:for-each>
   </xsl:for-each-group>
   </Table></Root>
</xsl:template>

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

</xsl:stylesheet>



I realize that the aid: namespace information makes this a 
bit hard to see. Sorry about that. At any rate, can anyone 
explain why the stylesheet strips out the <i> elements of the 
original <SS> content?  
The result looks, in part, like this:

<Cell aid:...>ELA3R2e The student identifies and infers meaning from  
common root words, common prefixes (e.g., un-, re-, dis-, in-), and  
common suffixes (e.g., -tion, -ous, -ly).</Cell>      <Cell. 
. .>Lesson 1:  
Prefixes Lesson 2: Suffixes Lesson 3: Root Words/Base Words</Cell>

I thought that the xsl:copy-of would keep the <i> tags.

Any ideas would be appreciated.

I have one other issue with this stylesheet. But that can wait.

Terry
Terry Ofner


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--