Groups | Blog | Home
all groups > dotnet xml > september 2004 >

dotnet xml : XSL - to insert a node



frandalc NO[at]SPAM swbell.net
9/10/2004 9:53:40 AM
[quoted text, click to view]

<xsl:for-each select="DataRecords/Point">
<xsl:text disable-output-escaping="yes">&lt;Record&gt;</xsl:text>
<Point>
<xsl:attribute name="Alias"><xsl:value-of select="@Alias" /></xsl:attribute>
<xsl:attribute name="Value"><xsl:value-of select="@Value" /></xsl:attribute>
<xsl:attribute name="Status"><xsl:value-of select="@Status" /></xsl:attribute>
<xsl:text disable-output-escaping="yes">&lt;/Record&gt;</xsl:text>
</xsl:for-each>

Beniamin Tecar
9/10/2004 12:15:57 PM
Hi,
I have an xml :

<DataRecords>
<Point Alias='A' Value='1' Status='0' />
<Point Alias='B' Value='2' Status='0' />
</DataRecords>
I have needed by an XSL to insert a node between <DataRecords> and <Point>

Example :

<DataRecords>
<Record>
<Point Alias='A' Value='1' Status='0' />
</Record>
<Record>
<Point Alias='B' Value='2' Status='0' />
</Record>
</DataRecords>

Can anyone help me?

Thanks

Beni




Martin Honnen
9/10/2004 1:39:42 PM


[quoted text, click to view]


[quoted text, click to view]

Simply use the identity transformation and add one template for <Point>
elements that wraps them into a <Record> element:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" encoding="UTF-8" />

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

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

</xsl:stylesheet>

--

Martin Honnen
AddThis Social Bookmark Button