Subject: Re: [xsl] Multiple arguments in one test From: Lars Huttar <lars_huttar@xxxxxxx> Date: Tue, 16 Nov 2010 14:29:48 -0600 |
On 11/16/2010 12:48 PM, Sharon_Harris@xxxxxxxxxxxxxxxxxxxx wrote: > How do I perform a test to find an element whose attribute value equals a > specific value and if the element itself contains specific text? For > example, I want to find a "p" element that has an "outputclass" attribute > whose value is "SupportInfo" and when those conditions are met, does that > "p" element contain the keyword "Yes". And once all of those conditions are > met, then do something (for example, output "this works"). > > XML snippet: > ------------------- > <p outputclass="SupportInfo">Yes</p> > > > I have tried combining all arguments into 1 test but the latter part of the > test is ignored. > > XSLT snippet: > --------------------- > <xsl:choose> > <xsl:when test="//@outputclass='SupportInfo' and contains(., 'Yes')"> The problem here is that the context for the contains(., 'Yes') is not the same as the context for @outputclass. Thus the above expression is asking, in effect, "Is there an @outputclass attribute anywhere (on any kind of element) with a value of 'SupportInfo', and does the current context node (having no relationship to any aforementioned @outputclass attributes) have a string value containing 'Yes'?" What you probably want instead is something like <xsl:choose> <xsl:when test="@outputclass='SupportInfo' and contains(., 'Yes')"> assuming that this code appears inside a for-each or apply-templates that is selecting p elements. "//" at the beginning of an XPath expression means "any descendant of the root of the document containing the context node". If you were trying to use this to output something for p anywhere in the document, you'll need to use a for-each or apply-templates select="//p". Lars
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Multiple arguments in one, Michael Dykman | Thread | [xsl] Stumped: XSL 1.0 recursive te, daniel whitney |
Re: [xsl] replacing of characters b, Brandon Ibach | Date | Re: [xsl] Stumped: XSL 1.0 recursiv, Brandon Ibach |
Month |