Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Xslt Choose in XML

Xslt Choose in XML

? Using <xsl:choose> in XSLT (XML)

<xsl:choose> is like an if-else if-else control structure in XSLT. It lets you apply conditional logic to your transformation based on XML data values.


How <xsl:choose> Works

  • Contains multiple <xsl:when test="..."> elements to test conditions.

  • Optional <xsl:otherwise> element for the default case if no conditions match.


Example

XML Input

<person>  <age>20</age></person>

XSLT with <xsl:choose>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">  <xsl:template match="person">    <div>      <xsl:choose>        <xsl:when test="age &lt; 18">          <p>Minor</p>        </xsl:when>        <xsl:when test="age &gt;= 18 and age &lt; 65">          <p>Adult</p>        </xsl:when>        <xsl:otherwise>          <p>Senior</p>        </xsl:otherwise>      </xsl:choose>    </div>  </xsl:template></xsl:stylesheet>

Explanation

  • Checks the <age> value.

  • Outputs "Minor" if age < 18.

  • Outputs "Adult" if age between 18 and 64.

  • Outputs "Senior" otherwise.


Resulting Output (HTML)

<div>  <p>Adult</p></div>

Summary

  • Use <xsl:choose> for branching logic.

  • Use multiple <xsl:when> for conditions.

  • Use <xsl:otherwise> for default/fallback.


Would you like me to create a full working example with XML, XSLT, and instructions?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql