I'm looking for a stylesheet which prints the name of each node including its value. Getting the value is easy but I don't know how to get the name of each node. Here's the basic template:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" encoding="UTF-8" />
<xsl:template match="/">
<xsl:for-each select="/">
???
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Could anyone give me a hint?
Thanks, Robert
This complete transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vQ">"</xsl:variable>
<xsl:template match="*">
<xsl:value-of select=
"concat(name(), ' = ', $vQ, ., $vQ, '
')"/>
<xsl:apply-templates select="*"/>
</xsl:template>
</xsl:stylesheet>
when applied on any XML document, such as this:
<nums>
<num>01</num>
<num>02</num>
<num>03</num>
<num>04</num>
<num>05</num>
<num>06</num>
<num>07</num>
<num>08</num>
<num>09</num>
<num>10</num>
</nums>
produces exactly the wanted, correct result:
nums = "01020304050607080910"
num = "01"
num = "02"
num = "03"
num = "04"
num = "05"
num = "06"
num = "07"
num = "08"
num = "09"
num = "10"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With