【发布时间】:2012-08-21 15:25:59
【问题描述】:
我得到了带有“xsi:schemaLocation="location1 location2 ...”和很多“xmlns:someNs”的xml文件。 虽然命名空间将被复制到新文档中,但 schemaLocations 不是,我真的无法弄清楚它们被删除的原因(所有命名空间和 schemaLocations 也在我的样式表中)。
Google 表示,如果在文档中不使用它们或类似的东西,它们将被删除,我必须自己添加它们,但似乎我不能......我正在使用 xalan 管道来管道一些基本的转换,现在我试图在管道的末端添加一个样式表来再次添加位置。这是我的最后一张纸:
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*">
<xsl:attribute name="xsi:schemaLocation">
<xsl:text>MYLOCATION</xsl:text>
</xsl:attribute>
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
我有几个带有元素标签的变体,没有副本...最好的结果是一个带有 schemaLocation 的双根元素和一个带有我真的无法弄清楚的所有命名空间的双根元素。
感谢您的帮助;)
€: 似乎我所有的个人样式表都在工作,除了 xalan 管道。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:pipe="http://xml.apache.org/xalan/PipeDocument"
extension-element-prefixes="pipe"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="someschema"
>
<xsl:param name="source"/>
<xsl:param name="target"/>
<!-- I think this block has no effect -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<pipe:pipeDocument
source="{$source}"
target="{$target}">
<stylesheet href="sheet1.xsl"/>
<stylesheet href="sheet2.xsl"/>
<stylesheet href="sheet3.xsl"/>
</pipe:pipeDocument>
</xsl:template>
</xsl:stylesheet>
Xalan 不再使用 -IN 和 -OUT 调用,我认为这就是我丢失位置的地方,尽管我不明白为什么 xmlns 声明仍在输出中。每张工作表都有自己的身份转换,如果不使用管道,则可以按预期工作。
【问题讨论】: