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

Re: Getting Unexpected Results from .//* = $set-of-el

Subject: Re: Getting Unexpected Results from .//* = $set-of-elements
From: "G. Ken Holman g.ken.holman@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 24 Feb 2018 00:18:15 -0000
Re:  Getting Unexpected Results from .//* =  $set-of-el
Ignore that second expression ... I wrote it too
hastily and I'm now back at my desk to think about it.

This would work I think:

  <xsl:value-of select="some $this in .//* satisfies
                        some $that in $elements-to-keep
                        satisfies $this is $that"/>

I hope this helps better than the incorrect expression provided earlier!

. . . . . . Ken

At 2018-02-23 23:37 +0000, G. Ken Holman g.ken.holman@xxxxxxxxx wrote:
Your operands of "=" are nodes, and so you are
checking the *value* of the elements when you say:

.//* = $elements-to-keep

I doubt you wanted the *value* (concatenated
string of descendent text nodes), but you probably want the identity.

For identity you could do something like:

.//*/generate-id(.) = $elements-to-keep/generate-id(.)

Or more formally along the lines of (untested):

    some $elem in .//* satisfies
    ( for $each in $elements-to-keep return $elem is $each )

Because of my time limitation I've just thrown
this together and haven't tested it ... and I
haven't run your data ... but given you have
key('elementsById',$id,.) I suspect you are not
interested in the string value of each of the elements but their identity.

I hope this is helpful.

. . . . . Ken

At 2018-02-23 23:10 +0000, Eliot Kimber ekimber@xxxxxxxxxxxx wrote:

I'm implementing a filtering process where I
want to filter out everything except the
ancestors of specified elements (user provides
a list of IDs to keep), as well as specific
subelements of the ancestors (e.g., header elements within HTML sections).

I'm using Saxon PE 9.7.0.19 (as included with
Oxygen 19.1) and and XSLT 2 template. The source doc is XHTML:

<?xml version="1.0" encoding="UTF-8"?>
..
At the start of my processing I create a
variable that is the list of elements to keep:

    <xsl:variable name="elements-to-keep" as="element()*"
      select="
      for $id in $element-ids-for-filtering
      return key('elementsById', $id, .)
      "
    />

I've verified that this produces the expected list of elements.

I then filter like so, here in the context of a
template that handles html section elements:


<xsl:template mode="filter-by-element-id" match="xhtml:section | xhtml:div" priority="10"> <xsl:param name="elements-to-keep" as="element()*" tunnel="yes"/>

    <xsl:choose>
      <xsl:when test=". = $elements-to-keep">
        <xsl:next-match/>
      </xsl:when>
      <xsl:when test=".//* = $elements-to-keep">
        <xsl:copy>
          <xsl:apply-templates mode="#current" select="@*, *"/>
        </xsl:copy>
      </xsl:when>
      <xsl:otherwise>
          <xsl:message>+ [DEBUG]
filter-by-element-id:   Section does not
contain any elements to keep, ignoring it.</xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

o;?What I think I'm saying is:

IF current element is in $elements-to-keep,
keep it (next match copies it to output)
IF any descendant of current element is in
$elements-to-keep, process the current element
Otherwise ignore the element.

In my test data I have this figure element:

<figure id="x88B6B95AEAD3
 <img id="x88B6B95AEADC" />
</figure>

If I specify the ID of the figure, the result
is as expected--I get the figure and all of the
ancestor sections and nothing else.

However, if I specify the ID of the img
element, I get not only the section I want but
other sections, because the second <when> in
the choice above resolves as true() when it should not.

Through experimentation I determined that the
variable is whether or not the element with the ID is an empty element or
not.

If the element is not empty, I get the correct behavior.


If the element is empty, I get the incorrect behavior.

Why would I be getting this behavior?

Could this be a Saxon bug or is there some
subtlety in the "=" operator that I'm missing?

What's particularly odd is that I'm getting a
false positive from elements that do not have
the element in $elements-to-keep as a descendant.

Thanks,

Eliot
--
Eliot Kimber
http://contrext.com


--
Contact info, blog, articles, etc. http://www.CraneSoftwrights.com/s/ |
Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
Streaming hands-on XSLT/XPath 2 training class @ US$45 (5 hours free) |

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.