Search for a specific <tag> and divide the value inside the <tag> by X [duplicate]

StackOverflow https://stackoverflow.com/questions/22872507

  •  28-06-2023
  •  | 
  •  

Pergunta

I'm new to XSLT, can someone give me a hand with this?

When in the source xml exists the tag , the value of that field has to be divided by 100.

In other words:

<value>44000</value> has to be transformed to <value>440</value>

The original xml can have any structure, the XSLT needs to iterate through the nodes and find that tag.

Thanks!

Foi útil?

Solução

Use the identity transformation template

  <xsl:template match="@*|node()">
    <xsl:copy>
       <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
   </xsl:template>  

and

<xsl:template match="foo">
  <xsl:copy>
    <xsl:value-of select=". div 100"/>
  </xsl:copy>
</xsl:template>

where foo is the name of the element where you want to change the value.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top