Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT: Selective Node Handling
    text
    copied!<p>I have the following xsd snippet:</p> <pre><code>&lt;xs:complexType name="HighSchoolType"&gt; &lt;xs:sequence&gt; &lt;xs:element name="OrganizationName" type="core:OrganizationNameType"/&gt; &lt;xs:group ref="core:OrganizationIDGroup" minOccurs="0"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; </code></pre> <p>I want to handle xs:element tags differently than xs:group tags, while completely ignoring xs:annotation and xs:restriction tags. When I have an: </p> <ul> <li>xs:element tag, I want to copy it.</li> <li>xs:group tag, I want the output to contain the children of the xs:group tags' tag.</li> <li>Any other tag can be ignored, I don't want it in my output</li> </ul> <p>I've been trying to use:</p> <pre><code>&lt;xsl:template match="xs:complexType"&gt; &lt;xsl:copy&gt; &lt;xsl:choose&gt; &lt;xsl:when test="*[self::xs:element]|@*"&gt; &lt;xsl:copy-of select="."/&gt; &lt;/xsl:when&gt; &lt;xsl:when test="*[self::xs:group]|@*"&gt; &lt;xsl:apply-templates select="."/&gt; &lt;/xsl:when&gt; &lt;/xsl:choose&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; </code></pre> <p>I don't understand why this:</p> <pre><code>&lt;xsl:copy-of select="*[not(self::xs:annotation or self::xs:restriction)]|@*"/&gt; </code></pre> <p>...will exclude xs:annotation &amp; xs:restriction nodes while </p> <pre><code>&lt;xsl:when test="*[self::xs:element]|@*"&gt; &lt;xsl:copy-of select="."/&gt; &lt;/xsl:when&gt; </code></pre> <p>...returns everything while:</p> <pre><code>&lt;xsl:when test="*[self::xs:group]|@*"&gt; &lt;xsl:apply-templates select="."/&gt; &lt;/xsl:when&gt; </code></pre> <p>...never triggers:</p> <pre><code>&lt;xsl:variable name="core" select="document('CoreMain_v1.4.0.xsd')" /&gt; &lt;xsl:variable name="AcRec" select="document('AcademicRecord_v1.3.0.xsd')" /&gt; &lt;xsl:template match="xs:group[@ref]"&gt; &lt;xsl:variable name="name" select="substring-after(@ref, ':')" /&gt; &lt;xsl:choose&gt; &lt;xsl:when test="substring-before(@ref, ':') = 'AcRec'"&gt; &lt;xsl:apply-templates select="$AcRec//*[@name=$name]" /&gt; &lt;/xsl:when&gt; &lt;xsl:when test="substring-before(@ref, ':') = 'core'"&gt; &lt;xsl:apply-templates select="$core//*[@name=$name]" /&gt; &lt;/xsl:when&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; &lt;xsl:template match="xs:group[@name]"&gt; &lt;xsl:copy-of select="node()[not(self::xs:annotation|self::xs:restriction)]|@*"/&gt; &lt;/xsl:template&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