Lin, Jessica wrote:
I am converting xml to xml by using xslt. For some reason, my result
missed "xsl:" before schemaLocation. Could you please help me find
what's wrong?
[...]
And I use imported file copy.xslt during procession.
<xsl:template match="/ | node() | @* | comment() |
processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
My result xml file:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns:bp="http://directv.com/bitstreams/blueprint"
xmlns="http://directv.com/bitstreams/blueprint"
[...]
schemaLocation="http://directv.com/bitstreams/blueprint
[...]
You use an extended version of the copy idiom. It should copy all
elements including namespaces correctly. I tried your XML
file,.simplified the XSLT like the following and it outputs the 'xsi'
(I'm sure you meant 'xsi', not 'xsl') in front of the schemaLocation
attribute.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output indent="yes" />
<xsl:template match="/ | node() | @* | comment() |
processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Though technically it is possible that the prefix changes, it seems not
the case in your example. The namespace actually changes. Since you say
that you <xls:import /> the copy xslt file, the problem may lay in your
main file. If there's any instruction at all, any template at all, it
will supersede the copy xslt. This is due to import precedence rules
(copy.xslt is imported and has as such a lower precedence) and the fact
that most specific rules always come first. Thus, if your main xslt file
looks something like this (I hope not):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
xpath-default-namespace="http://directv.com/bitstreams/blueprint">
<xsl:import href="copy.xslt" />
<xsl:output indent="yes" />
<xsl:template match="/*">
<xsl:copy>
<xsl:apply-templates select="*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
your output will be off on the root node. But you must do something
different than that, because you actually change the schemaLocation
attribute, or you add it by hand somewhere in your code, without
attaching it to the namespace again. If somewhere you do create it by
hand, you can do the following to attach the namespace:
<xsl:attribute name="xsi:schemaLocation"
namespace="http://www.w3.org/2001/XMLSchema-instance" />
Though you don't need to specify any prefix here. If you don't the
processor will think one up for you.
Hth,
Cheers,
-- Abel Braaksma
http://www.nuntia.com
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--