我在谷歌上搜索了一个小时,我找到的答案都没有解决这个问题。
下面是我的xml的一个片段
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>foobar</groupId>
<artifactId>superpom</artifactId>
<version>0.1.0.5</version>
</parent>
<artifactId>common-parent</artifactId>
<version>0.2.0.4-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<protostuff.version>1.0.7</protostuff.version>
<version>2.0.12.0</version>
</properties>我想要的是将第一个“版本”节点的值替换为其他的值。
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>foobar</groupId>
<artifactId>superpom</artifactId>
<version>0.1.0.5</version>
</parent>
<artifactId>common-parent</artifactId>
<version>THIS HAS CHANGED</version>
<packaging>pom</packaging>
<properties>
<protostuff.version>1.0.7</protostuff.version>
<version>2.0.12.0</version>
</properties>到目前为止,这是我的xslt文件
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="pReplacement" select="'THIS HAS CHANGED'"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//version[2]">
<xsl:value-of select="$pReplacement"/>
</xsl:template>
</xsl:stylesheet>我一直在玩“匹配”的价值,但没有什么效果。我试过“版本”、"/version“、"version2”。什么都没起作用。我不知道这是否重要,但我使用红帽子服务器上的xsltproc来运行转换。有人能帮忙吗?
发布于 2015-08-20 20:47:47
使用
<xsl:template match="/project/version[1]">
<xsl:copy>
<xsl:value-of select="pReplacement"/>
</xsl:copy>
</xsl:template>https://stackoverflow.com/questions/32127871
复制相似问题