我需要遍歷一堆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]。 –