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

Re: Need an XPath expression for: $B is not contained

Subject: Re: Need an XPath expression for: $B is not contained in $A
From: "Eliot Kimber ekimber@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 14 Jun 2018 13:22:48 -0000
Re:  Need an XPath expression for: $B is not contained
This seems to work:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="xs"
  version="2.0">
  <xsl:template match="/">
    <xsl:variable name="doc" as="document-node()">
      <xsl:document>
      <root>
        <a>
          <c>
            <b>This is b 1</b>
          </c>
          <d>This is d</d>
        </a>
        <f>
          <c>
            <b>This is b 2</b>
          </c>
        </f>
      </root>
      </xsl:document>
    </xsl:variable>

    <xsl:variable name="A" as="element()" select="$doc/*/a"/>
    <xsl:variable name="B1" as="element()" select="$doc/*/a/c/b"/>
    <xsl:variable name="B2" as="element()" select="$doc/*/f/c/b"/>
    <result>
      <test>b1 in A: <xsl:value-of select="$B1/ancestor::* = $A"/></test>
      <test>b2 in A: <xsl:value-of select="$B2/ancestor::* = $A"/></test>
    </result>
  </xsl:template>
</xsl:stylesheet>

Produces:

<result>
<test>b1 in A: true</test>
<test>b2 in A: false</test>
</result>

Cheers,

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


o;?On 6/14/18, 7:22 AM, "Costello, Roger L. costello@xxxxxxxxx"
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

    Hi Folks,

    The variable $A contains an element.

    The variable $B contains an element.

    I need an XPath expression that determines if $B is not contained in $A.

    This XPath expression seems to work:

        not(index-of($B/ancestor::*,$A))

    but that seems awful, i.e., not straightforward, convoluted, and probably
inefficient.

    Is there a better (simpler, straightforward, efficient) XPath expression?

    /Roger

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.