xml - Match when text is equals to something xslt -


what i'm trying simple, can't seem working.

i have following xml:

<analysis>     <field>         <name>field_1</name>         <type>number</type>         <tag>number field number one</tag>     </field>     <field>         <name>field_2</name>         <type>text</type>         <tag>text field number one</tag>     </field>     <field>         <name>field_3</name>         <cell>a12</cell>         <type>excel</type>         <tag>value comes excel file</tag>     </field> </analysis> 

i want xml output this:

<table>     <thead>         <tr>             <th>nombre</th> // name in spanish             <th>tipo</th>   // type in spanish         </tr>     </thead>     <tbody>         <tr>             <td>number field number one</td>             <td>número</td>  // number in spanish         </tr>         <tr>             <td>text field number one</td>             <td>campo de texto</td>  // text field in spanish         </tr>         <tr>             <td>value comes excel file</td>             <td>excel (a12)</td>  // excel (cell)         </tr>     </tbody> </table> 

my transformation far next:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="2.0">      <xsl:output method="html" indent="yes"/>      <xsl:template match="/">         <xsl:apply-templates />     </xsl:template>      <xsl:template match="analysis">          <table>             <thead>                 <tr>                     <th>nombre</th>                     <th>tipo</th>                 </tr>             </thead>             <tbody>                 <xsl:apply-templates select="field[type != 'table']"/>                 <!-- have type called table i'm ignoring question , won't follow same scheme -->             </tbody>         </table>          <br />      </xsl:template>      <xsl:template match="campo[field != 'table']">          <tr>             <td>                 <xsl:value-of select="tag" />             </td>             <td>                 <xsl:apply-templates select="type"/>             </td>         </tr>      </xsl:template>      <!-- following templates don't match -->      <xsl:template select="type = 'excel'">         <xsl:param name="cell" select="preceding-sibling::node()/cell" />         <xsl:value-of select="concat('excel ', $cell)" />     </xsl:template>      <xsl:template select="type = 'number'">         <xsl:value-of select="'número'" />     </xsl:template>      <xsl:template select="type = 'text'">         <xsl:value-of select="'campo de texto'" />     </xsl:template>  </xsl:stylesheet> 

as code says, last templates don't match. how match tag when text equals something? output want, 'number', 'text' , 'excel' values instead of equivalents in spanish, want.

i've tried other things <xsl:template select="field[type = 'excel']">, same result.

"how match tag when text equals something?"

focusing on specific problem of matching element when it's text equals specific value, can use . references current context element accomplish 'matching' task, example :

<xsl:template match="type[.='text']">     <xsl:value-of select="'campo de texto'" /> </xsl:template> 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -