Xml
我正在向现有xsl样式表添加一个附加条件 简化的XML输入内容如下所示:Xml ,xml,xslt,xpath,Xml,Xslt,Xpath,我正在向现有xsl样式表添加一个附加条件 简化的XML输入内容如下所示: <form id="MY_CONTENT"> <variable id="processInfo"> <variable id="teacher"> <variable id="taxId" value="12345"/> <variable id="name" value="Nancy"/> </variab
<form id="MY_CONTENT">
<variable id="processInfo">
<variable id="teacher">
<variable id="taxId" value="12345"/>
<variable id="name" value="Nancy"/>
</variable>
<variable id="student">
<variable id="taxId" value="12345"/>
<variable id="name" value="Nancy"/>
</variable>
<variable id="student">
<variable id="taxId" value="23456"/>
<variable id="name" value="Will"/>
<variable id="tutoringtInformation">
<variable id="specialNeeds">
<variable id="description" value="Special Need"/>
</variable>
</variable>
</variable>
<variable id="student">
<variable id="taxId" value="98765"/>
<variable id="name" value="Dustin"/>
<variable id="tutoringtInformation">
<variable id="preferences">
<variable id="reason" value="Mornings"/>
</variable>
</variable>
</variable>
<variable id="student">
<variable id="taxId" value="784512"/>
<variable id="name" value="Steve"/>
<variable id="tutoringtInformation">
<variable id="available" value="false"/>
</variable>
</variable>
</variable>
现在xslt只过滤出类型为student的元素,其taxId与teacher元素上的taxId不同
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<result>
<xsl:for-each select="/form/variable[@id = 'processInfo']/variable[@id = 'student' and variable[@id = 'taxId']/@value != ../variable[@id = 'policyHolder']/variable[@id = 'taxId']/@value]">
<xsl:variable name="taxId" select="variable[@id = 'taxId']/@value"/>
<resultSet>
<xsl:copy-of select="/form/variable[@id = 'processInfo']/variable[@id = 'student' and variable[@id = 'taxId']/@value = $taxId]"/>
<xsl:copy-of select="/form/variable[@id = 'processInfo']/variable[@id != 'student']"/>
<xsl:copy-of select="/form/variable[@id != 'processInfo']"/>
</resultSet>
</xsl:for-each>
</result>
</xsl:template>
</xsl:stylesheet>
除此条件外,我还希望筛选出不具有以下任何条件或条件的学生元素:
具有子元素特殊需要的子元素tutoringt信息
具有子元素首选项的子元素tutoringt信息
在提供的XML输入中,它应该同时输出Will和Dustin。如何实现这种行为?您的口头描述包含子元素specialNeeds的子元素tutoringtInformation转换为XPath tutoringtInformation/specialNeeds,只有您没有根据其表示的数据类型命名任何子元素,而只有id属性为该类型命名的变量元素,因此您更希望变量[@id='tutoringtInformation']]/变量[@id='specialNeeds']。如果将其放入谓词,即方括号中的变量[@id='student'][变量[@id='tutoringtInformation']/变量[@id='specialNeeds']],则检查是否存在。因为您不希望您的元素具有这些类型的子/孙辈,所以将否定与not:variable[@id='student'][notvariable[@id='tutoringtInformation']/variable[@id='specialNeeds']]一起使用。您可以使用and或其他谓词添加第二个条件。谢谢!您通过使用or将特殊需求和首选项链接到同一谓词中,并与前面的筛选器链接,为我指明了正确的方向。