Reputation: 5220
<ClinicalDocument>
<entry>
<substaceAdministration>
<effectiveTime></effectiveTime>
</substaceAdministration>
</entry>
<entry>
<substaceAdministration>
<effectiveTime></effectiveTime>
</substaceAdministration>
</entry>
<entry>
<substaceAdministration>
</substaceAdministration>
</entry>
</ClinicalDocument>
I have to assert for each entry/substaceAdministration is effectiveTime element is present or not.
I have tried with this expression
<xsl:when test="count(ClinicalDocument/entry/substanceAdministration/effectiveTime)=1"/>
I am looking for advice on how to change my XPath expression to meet this requirement.
Upvotes: 1
Views: 359
Reputation: 10443
Your statement
test="count(ClinicalDocument/entry/substanceAdministration/effectiveTime)=1"
will only return true if there is one and only one <effectiveTime> element.
It would be easier to understand what you're trying to do with more of your xsl:template to look at. What is your context node? Are you tring to process each <entry> that has an <effectiveTime> descendant? If so, you could just use a template:
<xsl:template match="entry[descendant::effectiveTime]">...</xsl:template>
Upvotes: 0
Reputation: 60418
Instead of trying to count all instances of child elements, maybe you should count all instances without child elements (sorry about the formatting for this one; it's long):
<xsl:when
test="count(ClinicalDocument/entry/substanceAdministration[not(effectiveTime)])
= 0">
<!-- True when all substanceAdministration elements
have an effectiveTime child
-->
</xsl:when>
You could also do this check on a per-substanceAdministration basis in either a for-each loop or a template using something like this:
<!-- Assuming the current node is substanceAdministration -->
<xsl:if test="count(effectiveTime) = 1">
<!-- True when there is one and only one effectiveTime child -->
</xsl:if>
Upvotes: 1