evaluate-node issue

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

evaluate-node issue

JBryant
I tried to use evaluate-node as a way to implement cross-references and
ran into what seems to be a bug. Here are some bits that illustrate the
problem:

The XML:

<doc>
  <reftarget>Aim here.</reftarget>
  <ref target="/doc/reftarget">Aim at reftarget</ref>
</doc>

The XSL (stripped down FO stuff)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:saxon="http://saxon.sf.net/"
  exclude-result-prefixes="saxon">

  <xsl:template match="/">
    <output-doc>
      <xsl:apply-templates/>
    </output-doc>
  </xsl:template>

  <xsl:template match="reftarget">
    <block id="{generate-id()}"><xsl:apply-templates/></block>
  </xsl:template>

  <xsl:template match="ref">
    <basic-link
internal-destination="{generate-id(saxon:evaluate-node(@target))}">
      <xsl:value-of select="."/>
    </basic-link>
  </xsl:template>

</xsl:stylesheet>

The output:

<?xml version="1.0" encoding="UTF-8"?>
<output-doc>
  <block id="d1e3">Aim here.</block>
  <basic-link internal-destination="d1e3">/doc/reftarget</basic-link>
</output-doc>

What I expected:

<?xml version="1.0" encoding="UTF-8"?>
<output-doc>
  <block id="d1e3">Aim here.</block>
  <basic-link internal-destination="d1e3">Aim at reftarget</basic-link>
</output-doc>

As you can see, I got the string value of the attribute node I passed to
the evaluate-node function where I expected the string value of the ref
node. I also tried turning the target value into an element rather than an
attribute, but I got the same result.

Thanks for looking into this issue and for making Saxon in the first
place.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: evaluate-node issue

JBryant
Never mind. I just realized that evaluate-node sets the context to the
node being evaluated.

so select=".." got the value I wanted.

Sorry to have polluted the list with a non-issue.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)




[hidden email]
Sent by: [hidden email]
10/17/2005 01:45 PM
Please respond to
[hidden email]


To
<[hidden email]>
cc

Subject
[saxon] evaluate-node issue






I tried to use evaluate-node as a way to implement cross-references and
ran into what seems to be a bug. Here are some bits that illustrate the
problem:

The XML:

<doc>
  <reftarget>Aim here.</reftarget>
  <ref target="/doc/reftarget">Aim at reftarget</ref>
</doc>

The XSL (stripped down FO stuff)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:saxon="http://saxon.sf.net/"
  exclude-result-prefixes="saxon">

  <xsl:template match="/">
    <output-doc>
      <xsl:apply-templates/>
    </output-doc>
  </xsl:template>

  <xsl:template match="reftarget">
    <block id="{generate-id()}"><xsl:apply-templates/></block>
  </xsl:template>

  <xsl:template match="ref">
    <basic-link
internal-destination="{generate-id(saxon:evaluate-node(@target))}">
      <xsl:value-of select="."/>
    </basic-link>
  </xsl:template>

</xsl:stylesheet>

The output:

<?xml version="1.0" encoding="UTF-8"?>
<output-doc>
  <block id="d1e3">Aim here.</block>
  <basic-link internal-destination="d1e3">/doc/reftarget</basic-link>
</output-doc>

What I expected:

<?xml version="1.0" encoding="UTF-8"?>
<output-doc>
  <block id="d1e3">Aim here.</block>
  <basic-link internal-destination="d1e3">Aim at reftarget</basic-link>
</output-doc>

As you can see, I got the string value of the attribute node I passed to
the evaluate-node function where I expected the string value of the ref
node. I also tried turning the target value into an element rather than an

attribute, but I got the same result.

Thanks for looking into this issue and for making Saxon in the first
place.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: evaluate-node issue

Michael Kay
> Never mind. I just realized that evaluate-node sets the
> context to the node being evaluated.

Yes - this was a difficult thing to decide. If people put relative path
expressions in an attribute of an element, it's in many ways more natural,
but less logical, to make it relative to the element that holds the context
node. Probably I should have made the node holding the expression and the
node to use as the context node separate parameters.

Michael Kay




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: evaluate-node issue

JBryant
> Probably I should have made the node holding the expression
> and the node to use as the context node separate parameters.
>
> Michael Kay

Well, my misunderstanding is my own fault, as I should have read more
closely the first time. Still, if you wish to make things more obvious,
separate parameters would clarify the workings of the function. Perhaps
the parameter to specify the context node could be optional, with the
present behavior if no second parameter exists. That would keep code from
breaking when those of us who are using it now upgrade. However, I imagine
that you have many more pressing changes to make.

It's a great extension function, by the way. I was able to toss out a
nasty recursive template because of it. Of course, if I ever change
processors, I'll need that old template. But that's why there's version
control.

I'm not planning to change XSLT processors, though. Saxon is definitely
best of breed, even without extras such as the evaluate-node function. I
very much appreciate your work.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help