Reputation: 466
I am trying to implement one simple xslt, to add one node under the root node.
Here is my input.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<root a="a">
<itemizedlist role="type6" id="ecls_bio_becls_a3_a43205230.SL2392155.512">
<listitem id="ecls_bio_becls_a3_a43205230.SL6440405.513"><para id="ecls_bio_becls_a3_a43205230.SL35914597.514">Glasform mit Deckel auf dem Rost, Höhe 1</para></listitem>
<listitem id="ecls_bio_becls_a3_a43205230.SL35935428.515"><para id="ecls_bio_becls_a3_a43205230.SL6441139.516">Mikrowelle 600 Watt</para></listitem>
<listitem id="ecls_bio_becls_a3_a43205230.SL37145770.517"><para id="ecls_bio_becls_a3_a43205230.SL37145771.518">Schalotten, Lauch: 4 Minuten</para></listitem>
<listitem id="ecls_bio_becls_a3_a43205230.SL37151364.519"><para id="ecls_bio_becls_a3_a43205230.SL37151365.520">Fleisch, Gemüse, Nudeln: 10-12 Minuten</para></listitem>
<listitem id="ecls_bio_becls_a3_a43205230.SL42243432.521"><para id="ecls_bio_becls_a3_a43205230.SL42243433.522">danach</para></listitem>
<listitem id="ecls_bio_becls_a3_a43205230.SL42243434.523"><para id="ecls_bio_becls_a3_a43205230.SL42243435.524">Mikrowelle 1000 Watt</para></listitem>
<listitem id="ecls_bio_becls_a3_a43205230.SL42243436.525"><para id="ecls_bio_becls_a3_a43205230.SL42243437.526">Bouillon: 5-6 Minuten</para></listitem>
</itemizedlist>
</root>
I am implementing xsl to put one "dummy" div before all listitem nodes.
Here is xsl file :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="UTF-8" omit-xml-declaration="yes" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="itemizedlist[@role='type6']">
<xsl:copy>
<div class="recipe_placeholder"/>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Output is like this :
<root a="a">
<itemizedlist><div class="recipe_placeholder"/>
<listitem id="ecls_bio_becls_a3_a43205230.SL6440405.513"><para id="ecls_bio_becls_a3_a43205230.SL35914597.514">Glasform mit Deckel auf dem Rost, Höhe 1</para>
</listitem>
<listitem id="ecls_bio_becls_a3_a43205230.SL35935428.515"><para id="ecls_bio_becls_a3_a43205230.SL6441139.516">Mikrowelle 600 Watt</para>
</listitem>
<listitem id="ecls_bio_becls_a3_a43205230.SL37145770.517"><para id="ecls_bio_becls_a3_a43205230.SL37145771.518">Schalotten, Lauch: 4 Minuten</para>
</listitem>
<listitem id="ecls_bio_becls_a3_a43205230.SL37151364.519"><para id="ecls_bio_becls_a3_a43205230.SL37151365.520">Fleisch, Gemüse, Nudeln: 10-12 Minuten</para>
</listitem>
<listitem id="ecls_bio_becls_a3_a43205230.SL42243432.521"><para id="ecls_bio_becls_a3_a43205230.SL42243433.522">danach</para>
</listitem>
<listitem id="ecls_bio_becls_a3_a43205230.SL42243434.523"><para id="ecls_bio_becls_a3_a43205230.SL42243435.524">Mikrowelle 1000 Watt</para>
</listitem>
<listitem id="ecls_bio_becls_a3_a43205230.SL42243436.525"><para id="ecls_bio_becls_a3_a43205230.SL42243437.526">Bouillon: 5-6 Minuten</para>
</listitem>
</itemizedlist>
</root>
Question is that on the output i can't see the attributes of itemizedlist, that i am adding one "div" element , on xsl transformation. Output shows it as
<itemizedlist>
Desired one is that :
<itemizedlist role="type6" id="ecls_bio_becls_a3_a43205230.SL2392155.512">
What i am doing wrong ? Is there another parameter to protect attribute values or not ?
Many thanks your answers in advance!
Upvotes: 0
Views: 31
Reputation: 33000
You must copy the attributes of itemizedlist
before you start the next element <div>
:
<xsl:template match="itemizedlist[@role='type6']">
<xsl:copy>
<xsl:apply-templates select="@*" />
<div class="recipe_placeholder"/>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>
Upvotes: 1