Xpath help. Get childnode with variable name

Posted by Kim Andersen on Stack Overflow See other posts from Stack Overflow or by Kim Andersen
Published on 2010-06-10T13:42:26Z Indexed on 2010/06/10 13:52 UTC
Read the original article Hit count: 337

Filed under:
|
|

I have the following XML:

<StatsContainer>
  <Variant1>0</Variant1>
  <Variant2>0.5</Variant2>
  <Variant3>1.2</Variant3>
  <Variant4>4.1</Variant4>
  <Variant5>93.9</Variant5>
  <Variant6>0.3</Variant6>
  <Variant7>0</Variant7>
  <Variant8>0</Variant8>
  <Variant9>0</Variant9>
  <Variant10>0</Variant10>
  <Variant11>0</Variant11>
  <Variant12>0</Variant12>
  <GlobalVariant1>4.6</GlobalVariant1>
  <GlobalVariant2>40.4</GlobalVariant2>
  <GlobalVariant3>13.8</GlobalVariant3>
  <GlobalVariant4>2.8</GlobalVariant4>
  <GlobalVariant5>35.6</GlobalVariant5>
  <GlobalVariant6>2.8</GlobalVariant6>
  <GlobalVariant7>0</GlobalVariant7>
  <GlobalVariant8>0</GlobalVariant8>
  <GlobalVariant9>0</GlobalVariant9>
  <GlobalVariant10>0</GlobalVariant10>
  <GlobalVariant11>0</GlobalVariant11>
  <GlobalVariant12>0</GlobalVariant12>
  <MosaicType>Boligtype</MosaicType>
  <OverRepresentedVariant>5</OverRepresentedVariant>
</StatsContainer>

As you can see I have a number in the "OverRepresentedVariant"-tag. This number can change from time to time. What i Need is to grab the "Variant"-tag with the right number. In the above case I need to get the value from the "Variant5"-tag (93.9). Tomorrow the "OverRepresentedVariant"-value might have changed to 3, this would mean that I should now grab the "Variant3"-value instead.

So this is what I got. I have a variable called $btOver which contains the above XML. I also have a variable called $btId which contains the "OverRepresentedVariant"-value like this:

<xsl:variable name="btId" select="$btOver/OverRepresentedVariant" />

So now I need some help finding the Variant-tags with the right ID. The tags that I need will always be named "Variant" followed by an id. So how can I get the right tag?

Thanks a lot in advance folks.

/Kim Andersen

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xpath