0

我不确定这是否可能。是否有可能使用 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>是否<termType>具有状态 ND。然后,如果确实如此,请检查该<termName>部分中的<relation>。如果它们之间的唯一区别是其中一个以's'结尾,则删除<term>带有状态ND的:

<?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 是最好的方法吗?老实说,我在这里超出了我的深度。谢谢。

4

1 回答 1

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在 a中只有一个,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>

更合适。

于 2012-12-17T12:36:50.900 回答