我需要遍历一堆XML文档,并使用XSLT 2.0简单地更改一个属性的值。文档的其余部分以及文档名称必须相同。更改属性值而不创建新的输出文档?
是否可以简单地更改现有文档而不创建新文档作为转换的输出?或者我需要复制文件,更改属性并将它们命名为原始文件?
编辑
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:fn='http://www.w3.org/2005/xpath-functions' exclude-result-prefixes='xsl xs fn' xmlns:h="http://java.sun.com/jsf/html">
<xsl:output method="xml" encoding="utf-8"/>
<xsl:strip-space elements="*"/>
<xsl:param name="files" select="collection('./output?select=*.html')"/>
<xsl:template match="/">
<xsl:for-each select="$files">
<xsl:variable name="fileName" select="tokenize(base-uri(), '/')[last()]"/>
<xsl:result-document method="xhtml" href="new/{$fileName}">
<div>
<h:selectBooleanCheckbox value="pubs"/>
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</div>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
<xsl:template match="@src">
<xsl:variable name="folderName" select="tokenize(base-uri(), '/')[last()-2]"/>
<xsl:text>http://localserver.com/</xsl:text>
<xsl:value-of select="$folderName"/>
<xsl:text>/output/</xsl:text>
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
它不工作。仅选择文本节点。我怎样才能使这个工作?
“*不起作用。*”不是有用的描述。发布一个**可重现的例子,包括一个输入和期望的输出 - 参见:[mcve]。 –