【发布时间】:2015-08-12 14:41:18
【问题描述】:
想知道是否有人可以帮助解决我面临的 XSLT 问题。
我正在尝试创建一个 xslt 脚本,该脚本将输入一个 xml 文档并将几个字段的值更改为“xxxx”输入 xml 中的字段具有特定值(例如,如果用户名是 jbond)
如果可能的话,我希望在我的 XSLT 中包含这种情况,但是我遇到了困难。
我目前的 XML、XSLT、Output 和预期的输出如下
XML:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl"?>
<rootDoc>
<user>test</user>
<tel>12345</tel>
<zip>abcd</zip>
</rootDoc>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" >
<xsl:output method="xml" omit-xml-declaration="no" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:if test="user = 'test'">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template match="tel/text()">XXXX</xsl:template>
<xsl:template match="zip/text()">XXXX</xsl:template>
</xsl:stylesheet>
输出:
<?xml version="1.0" encoding="UTF-8"?>
<rootDoc/>
预期:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl"?><rootDoc>
<user>test</user>
<tel>XXXX</tel>
<zip>XXXX</zip>
</rootDoc>
【问题讨论】:
标签: java xml xslt xml-parsing transform