XPath: is it possible to combine queries

Consider the following XML:

<root>
  <steps>
    <step>1</step>
    <step>2</step>
    <step>3</step>
    <step>4</step>
  </steps>
  <stepDetails step="1">Details</stepDetails>
  <stepDetails step="2">Details</stepDetails>
  <stepDetails step="3">Details</stepDetails>
</root>

What I need to do is find all the steps that do not have the appropriate parameters. In the above example, only the "<step </step>" node will be returned.

Now I know that I can do this by requesting all the steps, iterating through the collection, and executing another request for each iteration. I hope there is a way to do this with just one request. Perhaps using something like a SQL IN statement and a subquery.

Any ideas or tips would be most valuable.

Thnx, Christoph

+5
source share
2 answers

Try the following:

/root/steps/step[not(. = /root/stepDetails/@step)]
+14
source

something like that?

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="xml" indent="yes"/>
  <xsl:key name="steps" match="//root/stepDetails" use="@step" />

  <xsl:template match="//root">
    <root>
      <steps>
      <xsl:for-each select="steps/step[not(key('steps',text()))]">
        <xsl:copy>
          <xsl:apply-templates select="@* | node()" />
        </xsl:copy>
      </xsl:for-each>
      </steps>
    </root>
  </xsl:template>



  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
0

All Articles