I have an XML input with this structure:
<address>
<ip>192.168.7.5</ip>
<netmask>16</netmask>
<wildcard-mask>0.0.0.255</wildcard-mask>
<enable-wildcard-mask>false</enable-wildcard-mask>
</address>
I want to create a XSLT transformation that takes this input and uses either the 'wildcard-mask' value if 'enable-wildcard-mask' is true, or the 'netmask' value if 'enable-wildcard-mask' is false. However, the netmask must be converted from this format "24" to "255.255.255.0" and the wildcard mask must be converted to a netmask (binary negated).
So the output of this XSLT should be something like:
<netmask>255.255.255.0</netmask>
if 'enable-wildcard-mask' is true, and
<netmask>255.255.0.0</netmask>
if 'enable-wildcard-mask' is false.
This is the skeleton XSLT code for testing:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="address">
<xsl:choose>
<xsl:when test="wildcard-mask and (enable-wildcard-mask/text()='true')">
<netmask type="string"><xsl:value-of select="wildcard-mask"/></netmask>
</xsl:when>
<xsl:when test="netmask">
<netmask type="string"><xsl:value-of select="netmask"/></netmask>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
How do I do the necessary bit-wise transformations in XSLT?