Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting XSLT for the input XML
    text
    copied!<p>I have an assignment on converting the input xml using xslt.</p> <p>My input xml file,</p> <blockquote> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"&gt; &lt;rs:data&gt; &lt;z:row ID="1" CK="B0011" Description="VSC" DTC="B0000" Variant="" AN="Y" Notes="" GCategory="M1" System="VOS" Ownership="EEP"/&gt; &lt;z:row ID="2" CK="B0012" Description="VSC_1" DTC="B0011" Variant="" AN="Y" Notes="" GCategory="M3" System="VOS" Ownership="EEP"/&gt; &lt;z:row ID="3" CK="B0013" Description="VSC_2" DTC="B0012" Variant="" AN="Y" Notes="" GCategory="M54" System="VOS" Ownership="EEP"/&gt; &lt;z:row ID="4" CK="B0014" Description="VSC_3" DTC="B0013" Variant="" AN="Y" Notes="" GCategory="M1" System="VOS" Ownership="EEP"/&gt; &lt;z:row ID="5" CK="B0015" Description="VSC_4" DTC="B0014" Variant="" AN="Y" Notes="" GCategory="M3" System="VOS" Ownership="EEP"/&gt; &lt;/rs:data&gt; &lt;/xml&gt; </code></pre> </blockquote> <p>Excepted XML Output:</p> <blockquote> <pre><code>&lt;DF&gt; &lt;Cage Revision="" RevisionDate="" CPType="Authored" Ext_Identifier=""&gt; &lt;Entities&gt; &lt;StdDTCs&gt; &lt;StdDTC Action="Insert" CK="B0011" Description ="VSC" DTC="B0000" Variant="" AN="Y" Notes="" GCategory="M1" System="VOS" Ownership="EEP"/&gt; &lt;StdDTC Action="Insert" CK="B0012" Description ="VSC_1" DTC="B0011" Variant="" AN="Y" Notes="" GCategory="M3" System="VOS" Ownership="EEP"/&gt; &lt;StdDTC Action="Insert" CK="B0013" Description ="VSC_2" DTC="B0012" Variant="" AN="Y" Notes="" GCategory="M54" System="VOS" Ownership="EEP"/&gt; &lt;StdDTC Action="Insert" CK="B0014" Description ="VSC_3" DTC="B0013" Variant="" AN="Y" Notes="" GCategory="M1" System="VOS" Ownership="EEP"/&gt; &lt;StdDTC Action="Insert" CK="B0015" Description ="VSC_4" DTC="B0014" Variant="" AN="Y" Notes=" " GCategory="M3" System="VOS" Ownership="EEP"/&gt; &lt;/StdDTCs&gt; &lt;ABCDs&gt; &lt;ABCD/&gt; ............... ............... ............... &lt;ABCD/&gt; &lt;/ABCDs&gt; &lt;/Entities&gt; &lt;/Cage&gt; &lt;/DF&gt; </code></pre> </blockquote> <p>I tried a bit on the xslt. </p> <blockquote> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; </code></pre> <p> </p> </blockquote> <pre><code>&lt;xsl:key name="UID" match="z:row/@ID" use="."/&gt; &lt;xsl:template match="/"&gt; &lt;DF&gt; &lt;Cage&gt; &lt;xsl:attribute name="Revision"&gt;&lt;xsl:value-of select="''"/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="RevisionDate"&gt;&lt;xsl:value-of select="''"/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="ChangePackageType"&gt;&lt;xsl:value-of select="'Authored'"/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="Ext_Identifier"&gt;&lt;xsl:value-of select="''"/&gt;&lt;/xsl:attribute&gt; &lt;xsl:apply-templates select="@*|node()"/&gt; &lt;/Cage&gt; &lt;/DF&gt; &lt;/xsl:template&gt; &lt;!-- &lt;xsl:template match="rs:data"&gt; &lt;Entities&gt; &lt;StandardDTCs&gt; &lt;xsl:apply-templates select="StandardDTC"/&gt; &lt;/StandardDTCs&gt; &lt;/Entities&gt; &lt;/xsl:template&gt; --&gt; &lt;xsl:template match="rs:data"&gt; &lt;StdDTCs&gt; &lt;StdDTC&gt; &lt;xsl:attribute name="Action"&gt;&lt;xsl:value-of select="'Insert'"/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="CK"&gt;&lt;xsl:value-of select="z:row/@CK"/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="Description"&gt;&lt;xsl:value-of select="z:row/@Description"/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="DTC"&gt;&lt;xsl:value-of select="z:row/@DTC"/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="Variant"&gt;&lt;xsl:value-of select="z:row/@DTC"/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="AN"&gt;&lt;xsl:value-of select=""/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="Notes"&gt;&lt;xsl:value-of select=""/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="GCategory"&gt;&lt;xsl:value-of select=""/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="System"&gt;&lt;xsl:value-of select=""/&gt;&lt;/xsl:attribute&gt; &lt;xsl:attribute name="Ownership"&gt;&lt;xsl:value-of select=""/&gt;&lt;/xsl:attribute&gt; &lt;/StdDTC&gt; &lt;/StdDTCs&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Help me in framing this xslt.</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