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]
Other format: [Raw text]

Re: Strange Parameter Behavior



Michael Peet wrote:
> Given the XML:
>
> <a id="1">
>   <b id="2">
>     <c id="3"/>
>     <c id="4"/>
>     <c id="5"/>
>     <c id="6"/>
>   </b>
>   <b id="7">
>     <c id="8"/>
>     <c id="9"/>
>     <c id="10"/>
>   </b>
>   <b id="11">
>     <c id="12"/>
>     <c id="13"/>
>     <c id="14"/>
>   </b>
> </a>
>
>
> And XSLT of:
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>
>   <xsl:output encoding="ascii" omit-xml-declaration="yes" indent="yes"/>
>   <xsl:strip-space elements="*"/>
>
>   <xsl:param name="param-id" select="/a/b/c[1]/@id"/>
>
>   <xsl:template match="/">
>     param-id: <xsl:value-of select="$param-id"/><br/>
>     prev: <xsl:value-of select="//c[@id
= $param-id]/preceding::c[1]/@id"/><br/>
>     next: <xsl:value-of select="//c[@id
= $param-id]/following::c[1]/@id"/><br/>
>   </xsl:template>
>
> </xsl:stylesheet>
>
>
> I get the following expected results when passing in a parameter:
>
> param-id: 12
> prev: 10
> next: 13

Well, since you didn't provide the value the parameter, we'll have to take
your word that the result is expected.

> However, when I don't pass anything in and let the default parameter take

> over, I get this output:
>
> param-id: 3
> prev: 6
> next: 4
>
> Could anyone explain this?  Is there a RTF at work here?  When I wrap the

> default parameter value with a string() function, the stylesheet returns
the
> expected results:
>
> param-id: 3
> prev:
> next: 4

The results you got are correct, and there is no RTF involved.  I can think
of several things that might be confusing you.  One is the existential
quantification of the = operator when a node-set is one of the operands.
The other is that the preceeding axis is a reverse-document-order axis, so
the predicate [1] may not give you what you expect.  Since wrapping the
default parameter value in a call to the string() function gives you what
you expect, you're probably getting tripped up by the behavior of the =
operator.  (The string() function will return the string value of the first
node in the node-set.)

Try this variation on your template:

  <xsl:template match="/">
    param-id: <xsl:value-of select="$param-id"/><br/>
    count: <xsl:value-of select="count($param-id)"/><br/>
    prev: <xsl:value-of select="//c[@id
= $param-id]/preceding::c[1]/@id"/><br/>
    prev with $param-id predicate: <xsl:value-of select="//c[@id
= $param-id[1]]/preceding::c[1]/@id"/><br/>
    next: <xsl:value-of select="//c[@id
= $param-id]/following::c[1]/@id"/><br/>
  </xsl:template>

Hope that helps...

Dave



 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]