Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Specify an element in a nodeset directly

From: "roy axenov" <r_axenov@----.-->
To: NULL
Date: 10/3/2006 1:29:00 PM


eric.goforth@g... wrote:
> Martin Honnen wrote:
> > eric.goforth@g... wrote:
> > > <xsl:value-of select="
> > > $myblahs/blah[/xpath1/xpath2/someintegervalue]/yada
> > > "/>
> >
> > $myblahs/blah
> > [/xpath1/xpath2/someintegervalue=position()]/yada
>
> Hmmm, that's not working for me.  If I put in a "1" or a
> "2" it works, but not with the "variable".

Your example is awfully vague. For better results, provide
a sample XML and a minimum XSLT demonstrating your problem.

> <xsl:template match="thing[(position() mod 2)=1]">
>    <xsl:param name="furballs"/>
>    <!-- This works-->
>    <xsl:value-of select="thingintegerfield1"/>
>    <!-- This does not work-->
>    <xsl:value-of select="
> $furballs/furball[1=thingintegerfield1]/furballmember
>    "/>
> </xsl:template>

First of all, the [1=thingintegerfield1] predicate should
be [position()=thingintegerfield1] if I understood
correctly what you're trying to do (it's hard to be sure
without a working example).

Even then, I'd say you don't understand how contexts work.
Let's assume this template matched the node
/foo[1]/bar[1]/thing[1]. What does thingintegerfield1 in
the XPath marked as 'This works' refer to then? The answer
is '/foo[1]/bar[1]/thing[1]/thingintegerfield1'. And what
does thingintegerfield1 in the XPath marked as 'This does
not work' refer to? '$furballs/furball/thingintegerfield1'.
What you probably need is current()/thingintegerfield1,
although, once again, it's hard to be sure without a
working example.

To demonstrate:

XML:

<?xml version="1.0" encoding="UTF-8"?>
<foo>
  <bar>
    <xyzzy>
      <int>3</int>
    </xyzzy>
  </bar>
  <nodeset>
    <node>
      <str>wrong (1)</str>
      <int>3</int>
    </node>
    <node>
      <str>wrong (2)</str>
      <int>2</int>
    </node>
    <node>
      <str>right (3)</str>
      <int>1</int>
    </node>
  </nodeset>
</foo>

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>
  <xsl:template match="/">
    <xsl:apply-templates select="descendant::xyzzy">
      <xsl:with-param name="ns" select="/foo/nodeset"/>
    </xsl:apply-templates>
  </xsl:template>
  <xsl:template match="/foo/bar/xyzzy">
    <xsl:param name="ns"/>
    My Int: <xsl:value-of select="int"/>
    Wrong: <xsl:value-of select="
      $ns/node[int=position()]/str"/>
    Right: <xsl:value-of select="
      $ns/node[current()/int=position()]/str"/>
  </xsl:template>
</xsl:stylesheet>

-- 
roy axenov



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent