【发布时间】:2021-05-24 09:12:40
【问题描述】:
在下面的示例中,我们尝试处理“LOC_NAME”元素的值,如果最后出现“前”字,那么我们将使用 xslt 1.0 删除:
谁能帮忙。
输入 XML:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<LOC_NAME>Front</LOC_NAME>
<LOC_NAME>Arapaoa Front.</LOC_NAME>
<LOC_NAME>Arapaoa Island. Front</LOC_NAME>
<LOC_NAME>North Stake Front Stbd No.31</LOC_NAME>
<LOC_NAME>North Stake No.35</LOC_NAME>
</root>
预期输出:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<LOC_NAME>Front</LOC_NAME>
<LOC_NAME>Arapaoa</LOC_NAME>
<LOC_NAME>Arapaoa Island.</LOC_NAME>
<LOC_NAME>North Stake Front Stbd No.31</LOC_NAME>
<LOC_NAME>North Stake No.35</LOC_NAME>
</root>
XSLT 代码:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/root">
<root>
<xsl:apply-templates/>
</root>
</xsl:template>
<xsl:template match="LOC_NAME">
<xsl:copy>
<xsl:choose>
<xsl:when test=".='Front'">
<xsl:value-of select="'Front'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
【问题讨论】:
-
@michael.hor257k - 很抱歉,很高兴向我推荐对我很有帮助的答案。
-
您需要明确要修改哪些元素。
"Front"与"Front."不同。还能有其他变种吗?
标签: xml xslt xpath xslt-1.0 xquery