简体   繁体   中英

xslt: whats the easiest way to do a negated selection?

Basically what I would like is something like this that finds all nodes where the ID cannot be lookup'ed up ('broken links') :

<xsl:variable name="failedIDLookups" select="//inventory/box[@boxtypeID != //boxtypes/@ID]"/>

But this is not working as expected - I suppose the syntax is wrong, what should be the correct way of doing this ?

I suspect you want

<xsl:variable name="failedIDLookups" select="//inventory/box[not(@boxtypeID = //boxtypes/@ID)]"/>

which then could be optimized with a key declaration (as a child of xsl:stylesheet )

<xsl:key name="boxtypes-ref" match="boxtypes" use="@ID"/>

and

<xsl:variable name="failedIDLookups" select="//inventory/box[not(key('boxtypes-ref', @boxtypeID))]"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM