Reputation: 3
I have the following XML example:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<document>
<name>Example</name>
<date>2020-10-31</date>
<level>X_LEGAL_ABC</level>
<bundle>
<b001>E_AT01</b001>
<example_id>00000000000007372165</example_id>
<field>
<field_value>EUR</field_value>
<fieldname>CUR007</fieldname>
</field>
<field>
<field_value>2018-06-30</field_value>
<fieldname>C207</fieldname>
</field>
<field>
<field_value>2014-07-01</field_value>
<fieldname>C206</fieldname>
</field>
</bundle>
<bundle>
<b001>E_AT01</b001>
<example_id>00000000000007372163</example_id>
<field>
<field_value>EUR</field_value>
<fieldname>CUR007</fieldname>
</field>
<field>
<field_value>2020-05-31</field_value>
<fieldname>C207</fieldname>
</field>
<field>
<field_value>2014-06-01</field_value>
<fieldname>C206</fieldname>
</field>
</bundle>
</document>
</root>
With the following XSLT file:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version='1.1' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<document>
<xsl:attribute name="name"><xsl:value-of select="/root/document/name"/></xsl:attribute>
<xsl:attribute name="date"><xsl:value-of select="/root/document/date"/></xsl:attribute>
<xsl:attribute name="level"><xsl:value-of select="/root/document/level"/></xsl:attribute>
<xsl:for-each select="/root/document/bundle">
<bundle>
<xsl:attribute name="Example_id"><xsl:value-of select="example_id"/></xsl:attribute>
<xsl:attribute name="B001"><xsl:value-of select="B001"/></xsl:attribute>
<xsl:for-each select="./field">
<field>
<xsl:attribute name="FIELDVALUE"><xsl:value-of select="field_value"/></xsl:attribute>
<xsl:attribute name="FIELDNAME"><xsl:value-of select="fieldname"/></xsl:attribute>
</field>
</xsl:for-each>
</bundle>
</xsl:for-each>
</document>
</xsl:template>
</xsl:stylesheet>
This delivers me a working new XML format:
<?xml version="1.0" encoding="UTF-8"?>
<document name="Example" date="2020-10-31" level="X_LEGAL_ABC">
<bundle Example_id="00000000000007372165" B001="">
<field FIELDVALUE="EUR" FIELDNAME="CUR007"/>
<field FIELDVALUE="2018-06-30" FIELDNAME="C207"/>
<field FIELDVALUE="2014-07-01" FIELDNAME="C206"/>
</bundle>
<bundle Example_id="00000000000007372163" B001="">
<field FIELDVALUE="EUR" FIELDNAME="CUR007"/>
<field FIELDVALUE="2020-05-31" FIELDNAME="C207"/>
<field FIELDVALUE="2014-06-01" FIELDNAME="C206"/>
</bundle>
</document>
However, i would like to have the field FIELDVALUE displayed as FIELD VALUE. So with a blank space in between. Is this possible within an XSLT file?
Can i change: <xsl:attribute name="FIELDVALUE"
Into something like: <xsl:attribute name="FIELD VALUE"
Is this possible? Because if i try to run it, it does not work.
I'm new to this XSLT work, so any help would be appreciated.
Best regards,
Michael
Upvotes: 0
Views: 406
Reputation: 116959
No, it is not possible*, because the XML specification does not allow spaces in the names of elements and attributes.
(*) It is kind of possible, if you construct your output as text - but the result will not be a well-formed XML document.
Upvotes: 1