Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>IF you are trying to select <strong>Activation</strong> elements, who have a <strong>Child</strong> element with a <strong>ChildTypeName</strong> of "GoodAppType1" then maybe you can use template matching to select such an element where it exists.</p> <pre><code>&lt;xsl:apply-templates select="//ns3:Activation[ns3:Children/ns3:Child/ns3:ChildTypeName='GoodAppType1']" /&gt; </code></pre> <p>Then, within the template that matches this, you can easily output the <strong>ApplicationType</strong></p> <pre><code>&lt;ApplicationType&gt;&lt;xsl:value-of select="ns3:Parent/ns3:TypeName" /&gt;&lt;/ApplicationType&gt; </code></pre> <p>And then, select the <strong>Child</strong> element with the required <strong>ChildTypeName</strong></p> <pre><code>&lt;xsl:apply-templates select="ns3:Children/ns3:Child[ns3:ChildTypeName='GoodAppType1']" /&gt; </code></pre> <p>And within the template that matches <strong>Child</strong> you can likewise output the <strong>Key</strong> and <strong>ChildTypeName</strong>.</p> <p>Try the following XSLT</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="MyNewNamespace" xmlns:ns3="someNs3" exclude-result-prefixes="ns3"&gt; &lt;xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/&gt; &lt;xsl:variable name="activationNode"&gt; &lt;xsl:text&gt;Activation&lt;/xsl:text&gt; &lt;/xsl:variable&gt; &lt;xsl:variable name="new-root-node"&gt; &lt;xsl:text&gt;MyNewRootNode&lt;/xsl:text&gt; &lt;/xsl:variable&gt; &lt;xsl:template match="/"&gt; &lt;xsl:element name="{$new-root-node}"&gt; &lt;xsl:apply-templates select="//ns3:Activation[ns3:Children/ns3:Child/ns3:ChildTypeName='GoodAppType1']"/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="ns3:Activation"&gt; &lt;xsl:element name="{$activationNode}"&gt; &lt;ApplicationType&gt; &lt;xsl:value-of select="ns3:Parent/ns3:TypeName"/&gt; &lt;/ApplicationType&gt; &lt;xsl:apply-templates select="ns3:Children/ns3:Child[ns3:ChildTypeName='GoodAppType1']"/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="ns3:Child"&gt; &lt;ValidChildTypeName&gt; &lt;xsl:value-of select="ns3:ChildTypeName"/&gt; &lt;/ValidChildTypeName&gt; &lt;ValidChildKey&gt; &lt;xsl:value-of select="ns3:Key"/&gt; &lt;/ValidChildKey&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>When run against your input XML, the following is output</p> <pre><code>&lt;MyNewRootNode xmlns="MyNewNamespace"&gt; &lt;Activation&gt; &lt;ApplicationType&gt;TestApplication&lt;/ApplicationType&gt; &lt;ValidChildTypeName&gt;GoodAppType1&lt;/ValidChildTypeName&gt; &lt;ValidChildKey&gt;someOtherKey&lt;/ValidChildKey&gt; &lt;/Activation&gt; &lt;/MyNewRootNode&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload