我是xslt新手。我有以下问题。我需要在xml中从特定元素(例如div)中删除特定属性(在本例中为theAttribute)。即
<html>
<head>...</head>
<body>
<div id="qaz" theAtribute="44">
</div>
<div id ="ddd" theAtribute="4">
<div id= "ggg" theAtribute="9">
</div>
</div>
<font theAttribute="foo" />
</body>
</html>成为
<html>
<head>...</head>
<body>
<div id="qaz">
</div>
<div id ="ddd">
<div id= "ggg">
</div>
</div>
<font theAttribute="foo" />
</body>
</html>其中属性theAtribute已被删除。我找到了这个,http://www.biglist.com/lists/xsl-list/archives/200404/msg00668.html,基于它我试图找到合适的解决方案。
即<xsl:template match="@theAtribute" />
将其从整个文档中删除...还有其他的,比如match,if choose等等,都不起作用..:-(你能在这方面帮我一下吗?对我来说,这听起来微不足道,但是使用xslt,我根本无法应付……
提前感谢所有人
发布于 2019-08-01 21:05:38
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:param name="status"/>
<!--If attribute is present change it -->
<xsl:template match="@status" >
<xsl:attribute name="status" select="$status"/>
</xsl:template>
<!-- If attribute is not present add it al last position -->
<xsl:template match="row[ not( @status ) ]" >
<xsl:copy>
<xsl:apply-templates select="@*"/>
<!-- put attribute in the last position -->
<xsl:attribute name="status" select="$status"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<!--identity template copies everything forward by default-->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>我有一个像这样的xml:
<row attribute1="value" >some stuff</row> 我在属性列表的末尾添加了一个来自外部值的状态。
\saxonee\bin\Transform.exe -xsl:my_script.xsl -s:rows.xml status=“已完成”
<row current_run="2019-07-29 19:00" status="completed">https://stackoverflow.com/questions/3116396
复制相似问题