使用XSLT删除复数

时间:2012-12-17 11:59:35

标签: xslt plural

我不确定这是否可行。使用xslt(理想情况下为xslt 1)是否可以通过xml文件并删除一个术语(如果它是另一个术语的复数形式)。我有这个:

<?xml version="1.0" encoding="utf-8"?>
<Zthes>
<term>
<termId>35518385342487469049732</termId>
<termUpdate>add</termUpdate>
<termName>Doctor</termName>
<termType>PT</termType>
<termStatus>active</termStatus>
<termApproval>candidate</termApproval>
<termCreatedDate>20121217T11:47:45</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20121217T11:48:39</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
</term>
<term>
<termId>19229419919329134598161</termId>
<termUpdate>add</termUpdate>
<termName>Doctors</termName>
<termType>ND</termType>
<termStatus>active</termStatus>
<termApproval>candidate</termApproval>
<termCreatedDate>20121217T11:48:14</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20121217T11:48:14</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<relation>
<relationType>USE</relationType>
<termId>35518385342487469049732</termId>
<termName>Doctor</termName>
</relation>
</term>
<term>
<termId>179468269297128829432204</termId>
<termUpdate>add</termUpdate>
<termName>Medical Centre</termName>
<termType>PT</termType>
<termStatus>active</termStatus>
<termApproval>candidate</termApproval>
<termCreatedDate>20121217T11:48:31</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20121217T11:48:53</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
</term>
<term>
<termId>109697087683409264068424</termId>
<termUpdate>add</termUpdate>
<termName>Hospitals</termName>
<termType>ND</termType>
<termStatus>active</termStatus>
<termApproval>candidate</termApproval>
<termCreatedDate>20121217T11:48:53</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20121217T11:48:53</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<relation>
<relationType>USE</relationType>
<termId>179468269297128829432204</termId>
<termName>Medical Centre</termName>
</relation>
 </term>
</Zthes>

如果<termName>的状态为ND,我希望能够查看<termType>。然后,如果是,请检查<termName>部分中的<relation>。如果它们之间的唯一区别是其中一个以“s”结尾,则删除状态为ND的<term>

<?xml version="1.0" encoding="utf-8"?>
<Zthes>
<term>
<termId>35518385342487469049732</termId>
<termUpdate>add</termUpdate>
<termName>Doctor</termName>
<termType>PT</termType>
<termStatus>active</termStatus>
<termApproval>candidate</termApproval>
<termCreatedDate>20121217T11:47:45</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20121217T11:48:39</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
</term>
<term>
<termId>179468269297128829432204</termId>
<termUpdate>add</termUpdate>
<termName>Medical Centre</termName>
<termType>PT</termType>
<termStatus>active</termStatus>
<termApproval>candidate</termApproval>
<termCreatedDate>20121217T11:48:31</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20121217T11:48:53</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
</term>
<term>
<termId>109697087683409264068424</termId>
<termUpdate>add</termUpdate>
<termName>Hospitals</termName>
<termType>ND</termType>
<termStatus>active</termStatus>
<termApproval>candidate</termApproval>
<termCreatedDate>20121217T11:48:53</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20121217T11:48:53</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<relation>
<relationType>USE</relationType>
<termId>179468269297128829432204</termId>
<termName>Medical Centre</termName>
</relation>
 </term>
</Zthes>

XSLT是最好的方法吗?老实说,我在这里已经超出了我的深度。感谢。

1 个答案:

答案 0 :(得分:1)

如果s连接符合所有使用的术语,则

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="term[termType = 'ND' and concat(relation/termName, 's') = termName]"/>

</xsl:stylesheet>

可能会这样做。它还假设relation/termName内只有一个term,只有第一个相关。

如果可能有几个那么可能

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="term[termType = 'ND' and relation/termName[concat(., 's') = ../../termName]]"/>

</xsl:stylesheet>

更合适。