c# - XSLT moving nodes into a list -
im new xslt , have next problem
<root> <parentnode> <childnode1>value1</childnode1> <childnode2>value2</childnode2> <childnode3>value3</childnode3> <childnode4>value4</childnode4> <childnodelist> </childnodelist> </parentnode> </root>
output want:
if there value in either childnode3 or childnode4 need move value childnodelist node , delete original node displayed following:
<root> <parentnode> <childnode1>value1</childnode1> <childnode2>value2</childnode1> <childnodelist> <value name="childnode3">value3</value> <value name="childnode4">value4</value> </childnodelist> </parentnode> </root>
my current xslt has next code unsure how test whether there value in node, , if how create new node. want seek avoid using "xsl:if" i've read it's not best practice.
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" > <xsl:output method="xml" indent="yes"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> <xsl:if test="commercialdataoutput\structuralvariable\spare1"> <!--unsure do here--> <xsl:template match='childnode3|childnode4'/>
i think need
<xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="parentnode[normalize-space(foo) or normalize-space(bar)]"> <xsl:copy> <xsl:apply-templates select="@* | node()[not(self::foo | self::bar)]"/> <list> <xsl:apply-templates select="foo | bar" mode="wrap"/> </list> </xsl:copy> </xsl:template> <xsl:template match="foo | bar" mode="wrap"> <value name="{local-name()}"> <xsl:apply-templates/> </value> </xsl:template>
where foo
, bar
elements want check , transform if 1 has content.
c# .net xml xslt xslt-1.0
No comments:
Post a Comment