xsl-list
[Top] [All Lists]

Re: [xsl] xsl:apply-templates in combination with xsl:choose

2009-08-26 08:12:34
Stefanie Haupt wrote:

<xsl:template match="filesystem">
.....

<xsl:choose>
 <xsl:when
test="file/document(.)/xh:html/xh:head/xh:link/attribute::rel[contains(.,'stylesheet')]">
   <xsl:apply-templates select="file" mode="neuerTest"/>
 </xsl:when>

 <xsl:when
test="file/document(.)/xh:html/xh:head/xh:title[contains(.,'Mag')]">
  <xsl:apply-templates select="file" mode="#default"/>
 </xsl:when>
</xsl:choose>
</xsl:template>

<xsl:template match="file" mode="neuerTest">
...
<xsl:template>

<xsl:template match="file" mode="#default">
...
<xsl:template>

The problem is that the first 'when' always turns true. So all files are
processed using the first argument. I tried testing for the other type
in first place and got the same result: The test I place first is always
true even if I made sure that in the documents to be processed the
things I test for are exclusive. Type B doesn't have a stylesheet
attribute and type A never contains 'Mag' in title.
There must be a syntactical error or am I using this at the wrong place?

Well inside of an xsl:template match="filesystem" the expression
  file/document(.)
gives you a sequence of document nodes of all 'file' child elements and that way

test="file/document(.)/xh:html/xh:head/xh:link/attribute::rel[contains(.,'stylesheet')]"
checks whether there is a link rel="stylesheet" element in at least one of the files referenced by all the 'file' child elements of the 'filesystem' element.

So you probably rather want e.g.

<xsl:template match="filesystem">
  <xsl:apply-templates select="file"/>
</xsl:template>

<xsl:template match="file">
  <xsl:choose>
<xsl:when test="document(.)/xh:html/xh:head/xh:link/attribute::rel[contains(.,'stylesheet')]">
      <xsl:apply-templates select="." mode="neuerTest"/>
    </xsl:when>
<xsl:when test="document(.)/xh:html/xh:head/xh:title[contains(.,'Mag')]">
      <xsl:apply-templates select="." mode="someOtherMode"/>
     </xsl:when>
   </xsl:choose>
</xsl:template>

<xsl:template match="file" mode="neuerMode">
 ...
</xsl:template>

<xsl:template match="file" mode="someOtherMode">
  ...
</xsl:template>
--

        Martin Honnen
        http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>