Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>This transformation</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" &gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:param name="ptopElementName" select="'RootElement'"/&gt; &lt;xsl:variable name="vTop" select= "/*/xs:element[@name=$ptopElementName]"/&gt; &lt;xsl:variable name="vNames" select="$vTop/descendant-or-self::*/@name"/&gt; &lt;xsl:variable name="vRefs" select="$vTop/descendant-or-self::*/@ref"/&gt; &lt;xsl:variable name="vTypes" select="$vTop/descendant-or-self::*/@type"/&gt; &lt;xsl:template match="node()|@*" name="identity"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="xs:element"&gt; &lt;xsl:if test= "@name=$vNames or @name=$vRefs or ancestor-or-self::*[@name=$ptopElementName]"&gt; &lt;xsl:call-template name="identity"/&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;xsl:template match="xs:complexType|xs:simpleType"&gt; &lt;xsl:if test= "@name=$vTypes or ancestor-or-self::*[@name=$ptopElementName]"&gt; &lt;xsl:call-template name="identity"/&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on the provided XML document:</strong></p> <pre><code>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"&gt; &lt;xs:element name="RootElement"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element ref="ChildElement"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt;&lt;/xs:element&gt; &lt;xs:element name="ChildElement"/&gt; &lt;xs:element name="UnusedElement"/&gt; &lt;/xs:schema&gt; </code></pre> <p><strong>produces the wanted, corect result:</strong></p> <pre><code>&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"&gt; &lt;xs:element name="RootElement"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element ref="ChildElement"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:element name="ChildElement"/&gt; &lt;/xs:schema&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