Reputation: 27
I need to access the attribute of a tag that exists several layers beneath the current tag.
For example: A snippet of the XML looks like this
<Content version="Title" action="add">
<ProgramContent>
<ContentMetaData>
<ContentId>
<HouseNumber>558960</HouseNumber>
<AlternateId idType="SeriesId" authoritativeSource="BCM">19714</AlternateId>
<AlternateId idType="EntityId" authoritativeSource="BCM">550133</AlternateId>
</ContentId>
</ContentMetaData>
</ProgramContent>
</Content>
and my code currently looks like this:
<xsl:for-each select="ns0:BxfMessage/ns0:BxfData/ns0:Content">
<xsl:if test="string(@version)= 'Title'">
<xsl:if test="string(//AlternateId[@idType ='SeriesId'])">
<test>hey</test>
</xsl:if>
</xsl:if>
</xsl:for-each>
I need to do a for-each loop on the content tag to check through all of them but then within that for-each loop I only want to continue operations if the attribute of the AlternateID tags doesn't contain seriesId. So if either of them are seriesId I want to end the if statement. How do I do this? As you can see I've tried an if statement that should check if the attribute idType is equal to SeriesId but it fails and doesn't return anything, am I doing something wrong?
Cheers
Upvotes: 1
Views: 98
Reputation: 2125
The function string()
returns a string, but what you want is a Boolean. Something like test=//AlternateId[contains(@idType, 'SeriesId')]
should work better.
Upvotes: 1
Reputation: 4739
So basically you want to loop over all <Content>
elements that don't have a <AlternateID>
element with the idType="SeriesId"
.
You can do that directly into the xsl:for-each
like this:
<xsl:for-each select="ns0:BxfMessage/ns0:BxfData/ns0:Content[descendant::ns0:AlternateID/@idType != 'SeriesId']">
Upvotes: 2