This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

"apply-templates" doesn't work for novice


I am a novice with XSL. Here is a simplified version of the XML 
document i am  trying to transform.



<Notebook>
<List>
<Cell>
<CellGroupData>
<List>
     <Cell>
         <String>This is a Title</String>
             <Style>
             <String>Title</String>
             </Style>
     </Cell>
</List>
</CellGroupData>
</Cell>
<List>
<Options>
     <Option>
         <Symbol>FrontEndVersion</Symbol>
         <String>4.1 for Microsoft Windows</String>
     </Option>
</Options>
</Notebook>



When I use a narrowing down approach for the above document like so:


<xsl:template match="Notebook">
  <xsl:apply-templates select="List/*"/>
</xsl:template>

<!--Cell Group Level-->
<xsl:template match="CellGroupData">
  <xsl:apply-templates select="List"/>
</xsl:template>

<xsl:template match="Cell/String">
<xsl:value-of select="String"/>
</xsl:template>


followed by my VALUE-OF style-specific template:

"<xsl:template match="Cell/Style[String='Title']">
&#64;Title:<xsl:value-of select="../String"/></xsl:template>"


I get exactly the result on the text output document that I want and 
expect. It looks like this: @Title:This is a title.

The problem is that my XML document is MUCH more complicated than the 
one shown above, so the "value-of" approach ends up being incredibly 
buggy and tedious because I have to get every instance listed: 
"data/list/data/cell/group/testdata/style/string" for every single 
style (of which there are hundreds). Also text with inline styles is 
weirdly situated and it is difficult to catch this way as well.

I would very much like to use an "apply-templates" approach to avoid 
this; but when i change the above style-specific template to:

"<xsl:template match="Cell/Style[String='Title']">
&#64;Title:<xsl:apply-templates select="../String"/></xsl:template>

I get no text at all. If I change one of the narrowing templates like 
the third one listed above(match="Cell/String) so that the value-of 
select ="." I get duplicates of all the text:

This is a title.@Title:This is a title.

Is there no happy medium between none or double using the 
apply-templates approach? I feel that there is something fundamental 
that i am missing here that is not allowing me to use the 
apply-templates approach. Can it be done, and if so how? An example 
of code WITH AN EXPLANATION of why it works would be VERY much 
appreciated.

Thanks very very much in advance

-- 
Greg Martel

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]