1
votes

I've got a XSLT transformation which changes name of node NADR_KOD to NADR_KOD2, and copies the rest of XML without change. Today I wanted to add another transformation which changes attribute to element (I found solution on stack) But these two transformations in one xslt don't work...

Problem appeared becaue I coudn't load 'date' attribute in SSIS. XML Source always returns date as null. Maybe you can help me with this issue?

Structure of XML:

<DATA>
<ACCIDENT date="...">


 <INFO>
 <TEMP>
  <NADR_KOD>
   <NADR_KOD>Code</NADR_KOD>
  </NADR_KOD>
 </TEMP>
 </INFO>

</ACCIDENT>
</DATA>

Here is what i wanted:

<DATA>
<ACCIDENT>
 <date>...</date>

 <INFO>
 <TEMP>
  <NADR_KOD>
   <NADR_KOD2>Code</NADR_KOD2>
  </NADR_KOD>
 </TEMP>
 </INFO>

</ACCIDENT>
</DATA>

I have a couple of similar transformations like these. Here is how I made this:

  <xsl:template match="ACCIDENT">
  <!-- output a filter element -->
  <xsl:element name="ACCIDENT">
    <!-- add the name attribute, using the source name attribute value -->


   <xsl:element name="date">
     <xsl:value-of select="@date"/>
   </xsl:element>

   <!-- add the rest of attributes without change -->
   <xsl:copy-of select="node()"/>
 </xsl:element>


 </xsl:template>

 <xsl:template match="NADR_KOD/NADR_KOD">
    <NADR_KOD2>
        <xsl:apply-templates select="@*|node()"/>
    </NADR_KOD2>
 </xsl:template>

This code doesn't change NADR_KOD into NADR_KOD2. Thanks in advance...

1

1 Answers

0
votes

I think instead of

<!-- add the rest of attributes without change -->
   <xsl:copy-of select="node()"/>

you simply want

<!-- run the child elements through the identity transformation template for copying
     or my templates for transforming -->
<xsl:apply-templates/>

then you can use

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

and of course your

 <xsl:template match="NADR_KOD/NADR_KOD">
    <NADR_KOD2>
        <xsl:apply-templates select="@*|node()"/>
    </NADR_KOD2>
 </xsl:template>

If you want to transform further elements then you can add templates for them.