Hi, everyone:
I am working on transforming a xml file from old version to new version. Here is the basic template which i am using:
<xsl:template match="*">
<xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
<xsl:copy-of select="@*"></xsl:copy-of>
<xsl:apply-templates></xsl:apply-templates>
</xsl:element>
</xsl:template>
However, new version of xml schema requires that all elements which has a text value should not be empty string. So old xml document such as:
<dataset>
<title> </title>
</dataset>
will be invalid in the new version. I tried to modify default template for text node. The new text template will check the text node if the text code is empty string, it will terminate the transformation, otherwise it will copy the value to the output xml. Here is the template:
<xsl:template match="text()">
<xsl:variable name="text-value" select="."/>
<xsl:if test="normalize-space($text-value) = ''">
<xsl:message terminate="yes">
<xsl:call-template name="output_message3_fail">
<xsl:with-param name="parent_node" select="name(parent::node())"/>
</xsl:call-template>
</xsl:message>
</xsl:if>
<xsl:value-of select="$text-value"/>
</xsl:template>
However, i found out if input looks like:
<dataset>
<title>My tile</title>
</dataset
the new text template will be called. If input looks like:
<dataset>
<title> </title>
</dataset>
the new text template will never be called and output will looks like
<dataset>
<title/>
</dataset>
So my approach - modifying the text template, doesn't work. Do you have any suggestion how to do this - if find an element with empty string, terminate the transformation.
Thank you very much!
By the way, i am using java xalan xslt processor.