XSLTGeneral questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
I have recently created an XSL transform that takes some XML and transforms it into some more XML.
I have hit a problem and i'm not sure if it is possible to do it in XSL.
I have THREE fields in my first XML file. <VEHICLEAGEYEARS>, <VEHICLEAGEMONTHS> and <TERM>
I need to transform these into one new field in my new XML file in the form of YYMM (Years and Months). I can convert them into months quite simply, i.e (VEHICLEAGEYEARS * 12) + VEHICLEAGEMONTHS + TERM.
But it needs to be in the form YYMM.
Any idea how this could be done?
I started with this but got stuck when the term came into the problem;
<NEW FIELD>
<xsl:for-each select="MOTOR">
<xsl:choose>
<xsl:when test="VEHICLEAGEYEARS[. < 10]">
<xsl:choose>
<xsl:when test="VEHICLEAGEMONTHS[. < 10]">
<xsl:value-of select="concat('0', VEHICLEAGEYEARS)" />
<xsl:value-of select="concat('0', VEHICLEAGEMONTHS)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('0', VEHICLEAGEYEARS)" />
<xsl:value-of select="VEHICLEAGEMONTHS" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="VEHICLEAGEMONTHS[. < 10]">
<xsl:value-of select="VEHICLEAGEYEARS" />
<xsl:value-of select="concat('0', VEHICLEAGEMONTHS)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="VEHICLEAGEYEARS" />
<xsl:value-of select="VEHICLEAGEMONTHS" />
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</NEW FIELD>
I used <xsl:value-of select="concat(format-number(VEHICLEAGEYEARS, "00"), format-number(VEHICLEAGEMONTHS, "00"))" /> as a test but when I transform it I get <NewField>NaNNaN</NewField> in the new XML.