xslt1 problem (sets?)

Discussion in 'XML' started by Tim, Apr 29, 2011.

  1. Tim

    Tim Guest

    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>
    Tim, Apr 29, 2011
    #1
    1. Advertising

  2. 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/people/keshlam/index.html

    {} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
    /\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
    Joe Kesselman, Apr 29, 2011
    #2
    1. Advertising

  3. Tim

    Tim Guest

    On Apr 29, 5:47 pm, Joe Kesselman <>
    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/people/keshlam/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
    Tim, May 2, 2011
    #3
  4. Tim

    Tim Guest

    On May 2, 9:45 am, Tim <> wrote:
    > On Apr 29, 5:47 pm, Joe Kesselman <>
    > 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/people/keshlam/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>
    <xsl:eek:therwise>
    <xsl:text>TRUE</xsl:text>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:template>
    Tim, May 2, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Debo
    Replies:
    3
    Views:
    607
    Swampmonster
    Dec 12, 2004
  2. flamesrock

    Problem involving sets...

    flamesrock, Apr 14, 2006, in forum: Python
    Replies:
    4
    Views:
    397
    Dave Hughes
    Apr 15, 2006
  3. Dennis Benzinger

    Problem with sets and Unicode strings

    Dennis Benzinger, Jun 27, 2006, in forum: Python
    Replies:
    14
    Views:
    490
    Fredrik Lundh
    Jun 29, 2006
  4. bassel

    problem with Sets

    bassel, Sep 21, 2006, in forum: Java
    Replies:
    7
    Views:
    368
    Mark Jeffcoat
    Sep 21, 2006
  5. ed
    Replies:
    2
    Views:
    441
    Chris Uppal
    Dec 8, 2006
Loading...

Share This Page