J
jjouett
I'm trying to preserve the newline characters in my transformed XML
(read from a file) to provide a meaningful line number when validation
errors occur. However, my current method which performs an XSL
transform prior to validation is removing all the newlines. The XSL is
simply adding a namespace:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns="urn:RegisteredUser-schema">
<!-- This will just set the namespace of the topmost object -->
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
The problem is that an input XML string which has newlines goes from:
<user>
<firstname>Joe</firstname>
<lastname>User</lastname>
</user>
to a string without newlines:
<user
xmlns="urn:RegisteredUserschema"><firstname>Joe</firstname><lastname>User</lastname></user>
So any subsequent validation failure states that an error occurred on
line 1. I would like to be able to preserve the newlines in the
original string representation of the file, so that the error message
displayed to the user is meaningful.
Thanks in advance
(read from a file) to provide a meaningful line number when validation
errors occur. However, my current method which performs an XSL
transform prior to validation is removing all the newlines. The XSL is
simply adding a namespace:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns="urn:RegisteredUser-schema">
<!-- This will just set the namespace of the topmost object -->
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
The problem is that an input XML string which has newlines goes from:
<user>
<firstname>Joe</firstname>
<lastname>User</lastname>
</user>
to a string without newlines:
<user
xmlns="urn:RegisteredUserschema"><firstname>Joe</firstname><lastname>User</lastname></user>
So any subsequent validation failure states that an error occurred on
line 1. I would like to be able to preserve the newlines in the
original string representation of the file, so that the error message
displayed to the user is meaningful.
Thanks in advance