XSLT-“;套用;更新到另一个文件
我有一些Tomcat配置,我正在尝试自动更改。可能是这样的:XSLT-“;套用;更新到另一个文件,xslt,Xslt,我有一些Tomcat配置,我正在尝试自动更改。可能是这样的: <web-app> <!-- many other configuration options here... --> <session-config> <session-timeout>30</session-timeout> </session-config> <!-- many other configuration optio
<web-app>
<!-- many other configuration options here... -->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<!-- many other configuration options here... -->
<web-app>
30
我只想更新一个值,而不去碰其他值。因此,我定义了一个具有相同结构的文件,其中只有我想要更改的值:
<web-app>
<session-config>
<session-timeout>15</session-timeout>
</session-config>
<web-app>
15
这是我的XSLT,将更新文件作为输入,将“默认”TC配置文件路径作为参数提供给它:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" />
<xsl:param name="tcInputFilePath" />
<xsl:param name="tcInputFile" select="document($tcInputFilePath)" />
<xsl:template match="/">
<xsl:apply-templates select="$tcInputFile/*" />
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
基本上,我想要一份$tcInputFile
的副本,并从更新文件中应用更改。我的猜测是,在遍历TC文件时,我需要某种方法在更新文件中查找相同的路径,然后测试该路径是否没有子节点,如果有,则应用的值而不是复制。我只是不知道在遍历时如何选择其他文档中的“同一节点”。帮助?有关类似问题的通用XSLT 3解决方案,请参见,尽管输入中有要更新的空元素,但对于您的情况,您需要解释并实现一种检查相关元素的方法。解决方案需要xsl:evaluate
,它仅在Saxon 9.8和9.9的商业版本中可用
由于Saxon 9.8和9.9所有版本都支持transform
函数,因此在这些XSLT 3处理器中,也可以通过动态生成样式表并运行它来解决此问题:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:axsl="http://www.w3.org/1999/XSL/Transform-alias"
exclude-result-prefixes="#all"
expand-text="yes"
version="3.0">
<xsl:param name="config-doc">
<web-app>
<foo-config>
<foo-value>foo</foo-value>
</foo-config>
<!-- many other configuration options here... -->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<!-- many other configuration options here... -->
<bar-config>
<bar-value>bar</bar-value>
</bar-config>
</web-app>
</xsl:param>
<xsl:output indent="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>
<xsl:variable name="stylesheet">
<axsl:stylesheet version="3.0" exclude-result-prefixes="#all">
<axsl:mode on-no-match="shallow-copy"/>
<xsl:for-each select="//text()[normalize-space()]">
<axsl:template match="{path()}">{.}</axsl:template>
</xsl:for-each>
</axsl:stylesheet>
</xsl:variable>
<xsl:template match="/">
<xsl:sequence select="transform(map { 'source-node' : $config-doc, 'stylesheet-node' : $stylesheet })?output"/>
</xsl:template>
</xsl:stylesheet>
福
30
酒吧