[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: what are node set fragments and why are they ruining my

Subject: Re: what are node set fragments and why are they ruining my life?
From: Phil Lanch <phil@xxxxxxxxxxxxxxx>
Date: Wed, 15 Dec 1999 12:02:27 +0000
xsl local name
"Mark D. Anderson" wrote:
> 
> - I still don't get what is different between a rtf and
> a node-set. I mean, I get that a rtf is on the result side
> and the node-set is on the input side. But how could a rtf
> not be a set of nodes? Under what circumstances will
> xt:node-set or sxf:node-set fail?

xt:node-set or sxf:node-set will always succeed in converting a rtf into
a node-set. the point is just that, when you've got a rtf and want a
node-set, you must call the function: there's no implicit conversion.

> - Phil Lanch and David Carlisle suggest using
> <xsl:for-each select="xt:node-set($members)">

ok, that wasn't quite right, so here's some more dirt on rtfs: they
actually contain a sort of placeholder node at the top, which itself
contains all the content you explicitly put into the rtf. so the above
selects the placeholder node; to get its element children, try -

<xsl:for-each select="xt:node-set($members)/*">

- and combine that with the xsl:value-of to xsl:copy-of change -

> Note that if I change the xsl:value-of at the end of the
> named template to a xsl:copy-of, I then get this from xt:

- which is needed because you need element nodes in your rtf, not a
single text node (or series of text nodes - same difference) which has
some numbers in it: you can't pass that to sum() -

then it works (I think) in xt, i.e. it outputs this:

file:/usr/home/phil/tests/tree/m.xml:3: member local-name=member, id=1
file:/usr/home/phil/tests/tree/m.xml:4: member local-name=member, id=2
member local-name=member, id=1
member local-name=member, id=2
member 1member 2

- and in saxon ...

> - I agree with Phil that both xt and saxon have a bug here.
> xt for not executing enough xsl:message instructions, and saxon for
> producing no result.

well, one saxon bug you're getting is a known one, viz. the second
sentence of this:

5.0/014 If xsl:output specifies method="text" and indent="yes", no error
is reported, and the output disappears into a black hole. Also, if
method="xml" or "html" and indent="yes", any text output after the last
end tag is lost. FIXED

(Note: FIXED means in unreleased version.)

to work around that for now, change to indent="no". then I get the
bizarre result - 

member local-name=member, id=1
member local-name=member, id=2
member local-name=RESULT-TREE-FRAGMENT, id=
member 1member 2

- which looks like a new bug to me. I haven't tried reducing it to a
minimal case yet. my xml & xsl are:

--

<?xml version="1.0"?>
<root>
  <member id="1">member 1</member>
  <member id="2">member 2</member>
</root>

--

<?xml version="1.0" ?>

<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:date="http://www.jclark.com/xt/java/java.util.Date"
  xmlns:xt="http://www.jclark.com/xt"
  xmlns:sxf="/com.icl.saxon.functions.Extensions"
  extension-element-prefixes="date xt sxf"
  exclude-result-prefixes="date sxf xt"
  >
  <xsl:output
     method="html"
     indent="no"
     doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"
  />
  <xsl:strip-space elements="*"/>

  <xsl:template match="root">
    <xsl:variable name="members">
      <xsl:call-template name="get_members"/>
    </xsl:variable>
    <xsl:for-each select="sxf:node-set($members)/*">
      <xsl:message>member local-name=<xsl:value-of
select="local-name(.)"/>, id=<xsl:value-of select="@id"/></xsl:message>
    </xsl:for-each>
    <xsl:value-of select="$members"/>
  </xsl:template>

  <xsl:template name="get_members">
    <xsl:variable name="result" select="*"/>
    <xsl:for-each select="$result">
      <xsl:message>member local-name=<xsl:value-of
select="local-name(.)"/>, id=<xsl:value-of select="@id"/></xsl:message>
    </xsl:for-each>
    <xsl:copy-of select="*"/>
  </xsl:template>

</xsl:stylesheet>

--

I'll have another look at it later - and also see if I can pin down any
XT bug.

> - Phil Lanch also suggested that the reason i got a tree frag was
> because i initialized the variable $members with content rather
> than a select. But how could I do otherwise, when I want to
> set it to the result of a call-template?

that's right: you couldn't do otherwise - I was giving a handy rule to
spot when you've got a rtf, so you can then handle it appropriately.

-- 

cheers

phil

"that monotonous state of the soul halfway between fulfillment
and futility which comes with life in the country" --- Musil


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.