Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Would it be simpler to remove the unwanted attributes using Regex?</p> </blockquote> <p>No, this is a very simple XSLT operation:</p> <p><strong>This transformation</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match= "Response/@*[contains('|Timeout|PersonKey|Object|Username|', concat('|',name(),'|') ) ]"/&gt; &lt;xsl:template match="@*"&gt; &lt;xsl:element name="{name()}"&gt; &lt;xsl:value-of select="."/&gt; &lt;/xsl:element&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;Kronos_WFC encoding="ASCII" version="1.0" WFCVersion="6.1" TimeStamp="01/5/2011 8:38AM"&gt; &lt;Response Status="Success" Timeout="1800" PersonKey="-1" Object="System" Username="1" Action="Logon" PersonNumber="1"&gt;&lt;/Response&gt; &lt;Response Status="Success" action="Load"&gt; &lt;ScheduleGroup ScheduleGroupName="SomeName" AllowsInheritance="false" AllowContract="false" IsEmploymentTerm="false" /&gt; &lt;ScheduleGroup ScheduleGroupName="GreatName" AllowsInheritance="true" AllowContract="false" IsEmploymentTerm="false" /&gt; &lt;ScheduleGroup ScheduleGroupName="BestName" AllowsInheritance="true" AllowContract="false" IsEmploymentTerm="false" /&gt; &lt;/Response&gt; &lt;Response Status="Success" Object="System" Action="Logoff"&gt;&lt;/Response&gt; &lt;/Kronos_WFC&gt; </code></pre> <p><strong>produces exactly the wanted, correct result</strong>:</p> <pre><code>&lt;Kronos_WFC&gt; &lt;encoding&gt;ASCII&lt;/encoding&gt; &lt;version&gt;1.0&lt;/version&gt; &lt;WFCVersion&gt;6.1&lt;/WFCVersion&gt; &lt;TimeStamp&gt;01/5/2011 8:38AM&lt;/TimeStamp&gt; &lt;Response&gt; &lt;Status&gt;Success&lt;/Status&gt; &lt;Action&gt;Logon&lt;/Action&gt; &lt;PersonNumber&gt;1&lt;/PersonNumber&gt; &lt;/Response&gt; &lt;Response&gt; &lt;Status&gt;Success&lt;/Status&gt; &lt;action&gt;Load&lt;/action&gt; &lt;ScheduleGroup&gt; &lt;ScheduleGroupName&gt;SomeName&lt;/ScheduleGroupName&gt; &lt;AllowsInheritance&gt;false&lt;/AllowsInheritance&gt; &lt;AllowContract&gt;false&lt;/AllowContract&gt; &lt;IsEmploymentTerm&gt;false&lt;/IsEmploymentTerm&gt; &lt;/ScheduleGroup&gt; &lt;ScheduleGroup&gt; &lt;ScheduleGroupName&gt;GreatName&lt;/ScheduleGroupName&gt; &lt;AllowsInheritance&gt;true&lt;/AllowsInheritance&gt; &lt;AllowContract&gt;false&lt;/AllowContract&gt; &lt;IsEmploymentTerm&gt;false&lt;/IsEmploymentTerm&gt; &lt;/ScheduleGroup&gt; &lt;ScheduleGroup&gt; &lt;ScheduleGroupName&gt;BestName&lt;/ScheduleGroupName&gt; &lt;AllowsInheritance&gt;true&lt;/AllowsInheritance&gt; &lt;AllowContract&gt;false&lt;/AllowContract&gt; &lt;IsEmploymentTerm&gt;false&lt;/IsEmploymentTerm&gt; &lt;/ScheduleGroup&gt; &lt;/Response&gt; &lt;Response&gt; &lt;Status&gt;Success&lt;/Status&gt; &lt;Action&gt;Logoff&lt;/Action&gt; &lt;/Response&gt; &lt;/Kronos_WFC&gt; </code></pre> <p><strong>Explanation:</strong></p> <ol> <li><p>The identity rule/template copies every node "as-is".</p></li> <li><p>The template overriding the identity rule that matches any attribute with name <code>Timeout</code>, <code>PersonKey</code>, <code>Object</code>, or <code>Username</code> has empty body and doesn't copy them ("deletes" them from the output)</p></li> <li><p>The template matching any attribute creates an element whose name is the name of the matched attribute and whose text node-child is the value of the matched attribute.</p></li> </ol> <p><strong>Remember</strong>: Using and overriding <strong><a href="http://www.dpawson.co.uk/xsl/sect2/identity.html">the identity rule</a></strong> is the most fundamental and powerful XSLT design pattern.</p>
 

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