1

I'm looking to dynamically print out elements which exist in a control list using only native XSLT2.0 functions.

<xsl:variable name="controlList">name</xsl:variable>

<M N="name" V="Bill Billson"/>
<M N="address" V="1234 street name"/>
<M N="country" V="United Kingdom"/>
<M N="phone" V="123456789"/>

Output Required:

Bill Billson

Ultimately however it will need to cope with multiple values in the control list e.g.

<xsl:variable name="controlList">name,address,phone</xsl:variable>

So far i have tried many different permutations but not getting the required results.

<xsl:value-of select="M[@N='{$controlList}']/@V"/>

or

  <xsl:for-each select="M">
        <xsl:value-of select="/[@name=$controlList]/@V"/>
  </xsl:for-each>

Any help would be greatly appreciated. This may not even be available with native XSLT2.0 functions

pdev84
  • 13
  • 2
  • I am trying to further extend this, by passing in first a label to be printed out, and secondly the name of the field to get the value from, is this possible? e.g controllist would be 'Full Name,name,Home Address,address, Mobile Number,phone' – pdev84 Jan 13 '15 at 10:29

1 Answers1

1

Define the variable as <xsl:variable name="controlList" select="'name', 'address', 'phone'"/>, then yo can use M[@N = $controlList]/@V. See http://xsltransform.net/6qVRKw1 for an example.

If you can't set up the first variable as a sequence of strings then compute a second e.g.

<xsl:variable name="controlList">name,address,phone</xsl:variable>
<xsl:variable name="controlSeq" select="tokenize($controlList, ',')"/>

and then you can also make the = comparison in

<xsl:value-of select="M[@N = $controlSeq]/@V"/>
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110