Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

497
Vistas
Get Value(XPath) using XSL Variable - xslt

While trying to parse the below xml,

<root>
<SelectValue>One</SelectValue> <!-- Tends to Vary -->
<SubRoot>  <!-- Iterate elements inside it using [ SelectValue] -->
    <One>One</One>
    <Two>Two</Two>
    <Three>Three</Three> 
</SubRoot>
</root> 

with below xsl,

    <xsl:template match="/root">
        <xsl:variable name="columns" select="SelectValue"/>
        <xsl:for-each select="SubRoot"> -->
                        <tr>
                            <td>
                                <xsl:value-of select="SubRoot/@*[local-name()=$columns]"/>
                            </td>
                        </tr>

  </xsl:for-each>

Retrieves an empty html-tags while i expect something like below,

 <table>
   <thead>
   <th>One</th>
   </thead>
   <tbody>
    <tr>
      <td>one</td>
    </tr>
   <tbody>
</table>

I am trying to pass the value inside <SelectValue> to get the nodes inside <SubRoot>

Any thoughts here ?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

I do not recognize the error message you quote (it doesn't even seem to be English), but I do get an error when trying to run your code. The reason is that your variable name is invalid; you need to change:

<xsl:variable name="$columns" select="..."/>

to:

<xsl:variable name="columns" select="..."/>

Use the $ prefix when referring to the variable, not when defining it.


Note also that an XPath expression beginning with a /is an absolute path, starting at the root node. Therefore none of your select expressions - with the exception of /root - will select anything. I am guessing you are trying to do something like:

<xsl:template match="/root">
    <xsl:variable name="columns" select="SelectValue"/>
    <tr>
        <td>
            <xsl:value-of select="SubRoot/*[local-name()=$columns]"/>
        </td>
    </tr>
</xsl:template>

which given your input example will return:

<tr>
  <td>One</td>
</tr>
over 4 years ago · Santiago Trujillo Denunciar

0

Within xsl:for-each select="SubRoot", the SubRoot is the context node, so you should not be selecting down to a further SubRoot. So you want

<xsl:for-each select="SubRoot">
     <tr>
          <td>
              <xsl:value-of select="@*[local-name()=$columns]"/>
          </td>
    </tr>
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda