【发布时间】:2017-06-23 15:10:07
【问题描述】:
说这是我的 xml
<?xml version="1.0" encoding="UTF-8"?>
<node>
<file name="abc.txt.bak">
<fileid value="112358"/>
</file>
<location value="Baker Street"/>
</node>
我想使用 xsl 通过删除文件名的 .bak 来转换此 xml。 预期的结果是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<node>
<file name="abc.txt">
<fileid value="112358"/>
</file>
<location value="Baker Street"/>
</node>
我的xsl文件是这样的,不行。它只是复制所有内容而不更改值。
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node/file/@name" >
<xsl:copy>
<xsl:attribute name="name">
<xsl:value-of select="substring-before(., '.bak')" />
</xsl:attribute>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
【问题讨论】:
-
只需删除
<xsl:copy>周围的包装<xsl:attribute>。 -
不,它不起作用
-
@siriuswangch "不,它不起作用" 不是吗? xsltransform.net/bEzjRJX
-
@michael.hor257k 不,你可以在这里试试,xsltransform.net