Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xslt1 problem (sets?)

Reply
Thread Tools

xslt1 problem (sets?)

 
 
Tim
Guest
Posts: n/a
 
      04-29-2011
hi, I have some documents that need to be processed in one way if the
section titles belong to a certain set of titles and another way if a
section title is not in that set. I thought I had a pretty clever
solution but alas it doesn't work
I'm using xsltproc on freebsd.

This isn't working, but it is what I've tried.
(1) get a node set created from splitting a given string of the
canonical section titles and call that $need. (say the titles are
'Red', 'Green' and 'Blue', just for testing).

(2) get a node set of section titles from a document and call that
$have. the titles match for a test case, 'Red', 'Green', and 'Blue'.

(3) calculate the intersection of $have and $need. If the number of
nodes in $have is greater than the number of nodes in the
intersection, we have a title that is not in the first list ($need).

However, my intersection is empty. Maybe someone can help me figure
out how to solve this problem, using any method at all (intersecting
sets or not).

thanks,
--Tim Arnold

<xsl:template match="/">
<xsl:variable name="need">
<xsl:copy-of select="exsl:node-
set(str:split('Green,Blue,Red',','))" />
</xsl:variable>

<xsl:variable name="have">
<xsl:for-each select="chapter//section/info/title">
<xsl:element name="token">
<xsl:value-of select="." />
</xsl:element>
</xsl:for-each>
</xsl:variable>

<xsl:copy-of select="exsl:node-set(set:intersection($have,
$need))" />
</xsl:template>
</xsl:stylesheet>
 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      04-29-2011
At a very quick glance, and assuming that set: and str: are also
referring to the EXSLT extensions (which are not necessarily supported
everywhere since they *are* extensions):

1) set:intersection appears to be defined as operating on node identity,
not string value.

2) By generating the xsl:variable value via the children of that
element, rather than via a select= attribute, you are creating a new
Temporary Tree (or, if you prefer the XSLT 1.0 terminology, a new Result
Tree Fragment). That's a new set of nodes, which will not have the same
node identity as nodes in the original document.

The result is that you're comparing a set of new text nodes containing
your strings, against a set of new nodes copied from the source
document... for identity. That isn't going to ever match.


--
Joe Kesselman,
http://www.love-song-productions.com...lam/index.html

{} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
/\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
 
Reply With Quote
 
 
 
 
Tim
Guest
Posts: n/a
 
      05-02-2011
On Apr 29, 5:47*pm, Joe Kesselman <(E-Mail Removed)>
wrote:
> At a very quick glance, and assuming that set: and str: are also
> referring to the EXSLT extensions (which are not necessarily supported
> everywhere since they *are* extensions):
>
> 1) set:intersection appears to be defined as operating on node identity,
> not string value.
>
> 2) By generating the xsl:variable value via the children of that
> element, rather than via a select= attribute, you are creating a new
> Temporary Tree (or, if you prefer the XSLT 1.0 terminology, a new Result
> Tree Fragment). That's a new set of nodes, which will not have the same
> node identity as nodes in the original document.
>
> The result is that you're comparing a set of new text nodes containing
> your strings, against a set of new nodes copied from the source
> document... for identity. That isn't going to ever match.
>
> --
> Joe Kesselman,http://www.love-song-productions.com...lam/index.html
>
> {} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
> /\ Stamp out HTML mail! *| "Put down the squeezebox & nobody gets hurt."


Hi Joe,
Thanks for the explanation. I wondered if I was comparing for identity
but lacked the knowledge to see it.

So now I know that isn't going to work. Can you point me in the right
direction for solving the problem? I'm obviously pretty new to xslt
and get the basics I think, but this situation is a real puzzle for
me. Not asking for a working solution, just a direction that might be
profitable to study. I used the 'set' functionality since that's how I
would solve the problem in a procedural language.

thanks for thinking about this,
--Tim Arnold
 
Reply With Quote
 
Tim
Guest
Posts: n/a
 
      05-02-2011
On May 2, 9:45*am, Tim <(E-Mail Removed)> wrote:
> On Apr 29, 5:47*pm, Joe Kesselman <(E-Mail Removed)>
> wrote:
>
>
>
>
>
>
>
>
>
> > At a very quick glance, and assuming that set: and str: are also
> > referring to the EXSLT extensions (which are not necessarily supported
> > everywhere since they *are* extensions):

>
> > 1) set:intersection appears to be defined as operating on node identity,
> > not string value.

>
> > 2) By generating the xsl:variable value via the children of that
> > element, rather than via a select= attribute, you are creating a new
> > Temporary Tree (or, if you prefer the XSLT 1.0 terminology, a new Result
> > Tree Fragment). That's a new set of nodes, which will not have the same
> > node identity as nodes in the original document.

>
> > The result is that you're comparing a set of new text nodes containing
> > your strings, against a set of new nodes copied from the source
> > document... for identity. That isn't going to ever match.

>
> > --
> > Joe Kesselman,http://www.love-song-productions.com...am/index..html

>
> > {} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
> > /\ Stamp out HTML mail! *| "Put down the squeezebox & nobody gets hurt."

>
> Hi Joe,
> Thanks for the explanation. I wondered if I was comparing for identity
> but lacked the knowledge to see it.
>
> So now I know that isn't going to work. Can you point me in the right
> direction for solving the problem? I'm obviously pretty new to xslt
> and get the basics I think, but this situation is a real puzzle for
> me. Not asking for a working solution, just a direction that might be
> profitable to study. I used the 'set' functionality since that's how I
> would solve the problem in a procedural language.
>
> thanks for thinking about this,
> --Tim Arnold


Well I do have something working but I think it could be better.
I create $need as a string of concatenated permissible titles.
Then I look at each first-level section title and see if $need
contains the title, putting the result (true or false) into a new
variable $mydecision.

After that loop, if 'false' is present in the $mydecision variable,
the decision is then false.

In this toy example that isn't too bad, but if someone had a title
named "Gree" my test would erroneously pass.

I'm still working on this problem--if anyone sees a more fruitful
method to think about please let me know.
thanks,
--Tim

<xsl:template match="/">
<xsl:variable name="need">
<xsl:value-of select="string('Red,Green,Blue)" />
</xsl:variable>

<xsl:variable name="mydecision">
<xsl:for-each select="d:chapter/d:section/d:info/d:title">
<xsl:value-of select="contains($need, text())" />
</xsl:for-each>
</xsl:variable>

<xsl:choose>
<xsl:when test="contains($mydecision,'false')">
<xsl:text>FALSE</xsl:text>
</xsl:when>
<xsltherwise>
<xsl:text>TRUE</xsl:text>
</xsltherwise>
</xsl:choose>
</xsl:template>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments