XML : Trying to access multiple nodes in a for each

In my XML there is multiple nodes ex. CAT1, CAT2, CAT3,...,CAT(N). and I want to display their values but it's dynamic and based of NUMOFCATS.

some psuedo code for that i want

  for(i=0;i<NUMOFCATS;i++){      String string = CAT;      append the value of i to string; //so if i=0 then string=CAT0      <xsl:value-of select="$string" />  }    

so then the results would display the value of

  CAT0  CAT1  ...  CAT(NUMOFCATS)    

edit: adding some sample XML

  <root>      <BIRD>ignore</BIRD>      <CAT1>fluffy</CAT1>      <CAT2>snuggles</CAT2>      <NUMOFPETS>2</NUMOFPETS>      <DOG1>wolfy</DOG1>      <DOG2>puppy</DOG2>  </root>    

XSLT

  <xsl:for-each select="root/*">      <fo:table-row height="8pt">          <fo:table-cell border-color="black" border-width="1pt"              border-style="solid">              <fo:block text-indent="5pt">                  <xsl:if test="substring(local-name(),1,3) = 'CAT'">                      <fo:inline color="red">                          <xsl:value-of select="." />                      </fo:inline>                  </xsl:if>              </fo:block>          </fo:table-cell>          <fo:table-cell border-color="black" border-width="1pt"              border-style="solid">              <fo:block text-indent="5pt">                  <xsl:if test="substring(local-name(),1,3) = 'DOG'">                      <fo:inline color="red">                          <xsl:value-of select="." />                      </fo:inline>                  </xsl:if>              </fo:block>          </fo:table-cell>      </fo:table-row>   </xsl:for-each>    

Result a table with

  fluffy       wolfy  snuggles     puppy    

and im using XSLT 1.0

Edit: Tried to clarify my question better, sorry I'm usually bad at asking questions.

Thanks in advance for any help.

No comments:

Post a Comment