Marcus1807
Marcus1807

Reputation: 11

xslt:key match with contains(text(),

I have to use xslt 1.0 and I have following xml:

<Root>
 <Alarm>
   <Name>short</Name>
    <FlagValues>Client, RunTime, Language</FlagValues>
 </Alarm>
 <Alarm>
   <Name>long</Name>
   <FlagValues>Client, Formatted, RunTime, Language</FlagValues>
 </Alarm>
</Root>

At the beginning of my xslt transformation I want to create a mapping with xsl:key..... I need all "Alarm"-nodes where the string "Formatted" is in the "FlagValues"-node. The Key should be the "Name".

So here is my try:

<xsl:key name="alarmNodes" match="Root/Alarm/FlagValues[contains(text(), 'Formatted')]" use="Name" />

But when I try to access it, it is empty:

<xsl:when test="key('alarmNodes', "'long'")">

My expected result is a node-Object containing this:

 <Alarm>
   <Name>long</Name>
   <FlagValues>Client, Formatted, RunTime, Language</FlagValues>
 </Alarm>

Any ideas whats going wrong?

Thanks Marcus

Upvotes: 1

Views: 50

Answers (1)

Daniel Haley
Daniel Haley

Reputation: 52858

You're selecting FlagValues in your match (and FlagValues doesn't have a child Name).

Try selecting Alarm instead...

<xsl:key name="alarmNodes" match="Root/Alarm[contains(FlagValues, 'Formatted')]" use="Name" />

You also have quoting issues in the test of your xsl:when, but you'd be getting an exception so that's probably just a typo.

Upvotes: 0

Related Questions