Please help me...
I have input XML document:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Object>
<GUID>201110180954525010129</GUID>
<Meta name="FILENAME" format="string" frate="" />
</Object>
</Root>
I need to transform it into the next xml:
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Object>
<GUID>201110180954525010129</GUID>
<FILENAME/>
</Object>
<Root>
I've created the next style sheet:
<?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" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<xsl:element name="Root">
<xsl:for-each select="Root/Object">
<xsl:element name="Object">
<xsl:element name="FILENAME">
<xsl:value-of select="Meta[@name='FILENAME']" />
</xsl:element>
<xsl:element name="GUID">
<xsl:value-of select="GUID" />
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
But when I trying to transform it, I get the next result:
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Object>
<GUID>201110180954525010129</GUID>
<FILENAME> </FILENAME>
</MAObject>
<Root>
How can I tell to interpret self-closing tags ?
C# transformation code:
var stylesheet = "styleSheet.xml";
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load("input.xml");
XslCompiledTransform xslTransform = new XslCompiledTransform();
xslTransform.Load(styleSheet);
XmlDocument xmlDocumentOutput = new XmlDocument();
XmlDeclaration xmlDocumentOutputDeclaration = xmlDocumentOutput.CreateXmlDeclaration("1.0", "utf-8", null);
xmlDocumentOutput.AppendChild(xmlDocumentOutputDeclaration);
using (XmlWriter xmlWriter = xmlDocumentOutput.CreateNavigator().AppendChild())
{
xslTransform.Transform(xmlDocument.CreateNavigator(), null, xmlWriter);
}
return xmlDocumentOutput;
I tried our samples with XslCompiledTransform, the output I get is
How do you run the transformation exactly, how do you look at the output? With XML an empty "foo" element can be marked up as
<foo></foo>
or<foo/>
or<foo />
, these forms are semantically equivalent. Why do you need a particular form? Is the output of the XSLT transformation not processed by an XML parser?[edit]Try whether replacing
with
at least ensures the FILENAME element you get is empty.