Hi all,
I have an xml structure looks like below:
XML Snippet
============
<?xml version="1.0" encoding="UTF-8"?>
<article>
<meta>
<production-dates printpubdate="2009" receiveddate="30Sep2008"
reviseddate="30Sep2008" acceptdate="30Oct2008"/>
</meta>
<abstract>This is an abstract</abstract>
</article>
I've defined a template for <production-dates> attributes, which is like
this:
Stylesheet Snippet
===================
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- For Production-Dates -->
<xsl:variable name="months" as="element()+">
<month name="Jan" num="January"/>
<month name="Feb" num="Febuary"/>
<month name="Mar" num="March"/>
<month name="Apr" num="April"/>
<month name="May" num="May"/>
<month name="Jun" num="June"/>
<month name="Jul" num="July"/>
<month name="Aug" num="August"/>
<month name="Sep" num="September"/>
<month name="Oct" num="October"/>
<month name="Nov" num="November"/>
<month name="Dec" num="December"/>
<month name="xxx" num="Xxx"/>
<month name="Xxx" num="Xxx"/>
</xsl:variable>
<xsl:template name="production_dates">
<xsl:text>(</xsl:text>
<xsl:choose>
<!-- Received date -->
<xsl:when test="//production-dates/@receiveddate">
<xsl:text>Received </xsl:text>
<xsl:for-each
select="//production-dates/@receiveddate">
<xsl:variable name="re" select="
'^([0-9a-z]{2})?([A-Za-z][a-z][a-z])([0-9]{4})$'"/>
<xsl:analyze-string select="." regex="{ $re
}">
<xsl:matching-substring>
<xsl:variable name="day"
select="regex-group(1)"/>
<xsl:sequence select="
concat(regex-group(1), ' ',
$months[(_at_)name eq regex-group(2)]/@num, ' ',
regex-group(3))"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:for-each>
</xsl:when>
<!-- Revised date -->
<xsl:when test="//production-dates/@reviseddate">
<xsl:text>; final version received </xsl:text>
<xsl:for-each
select="//production-dates/@reviseddate">
<xsl:variable name="re" select="
'^([0-9a-z]{2})?([A-Za-z][a-z][a-z])([0-9]{4})$'"/>
<xsl:analyze-string select="." regex="{ $re
}">
<xsl:matching-substring>
<xsl:variable name="day"
select="regex-group(1)"/>
<xsl:sequence select="
concat(regex-group(1), ' ',
$months[(_at_)name eq regex-group(2)]/@num, ' ',
regex-group(3))"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:for-each>
</xsl:when>
<!-- Accepted date -->
<xsl:when test="//production-dates/@acceptdate">
<xsl:text>; final version accepted </xsl:text>
<xsl:for-each
select="//production-dates/@acceptdate">
<xsl:variable name="re" select="
'^([0-9a-z]{2})?([A-Za-z][a-z][a-z])([0-9]{4})$'"/>
<xsl:analyze-string select="." regex="{ $re
}">
<xsl:matching-substring>
<xsl:variable name="day"
select="regex-group(1)"/>
<xsl:sequence select="
concat(regex-group(1), ' ',
$months[(_at_)name eq regex-group(2)]/@num, ' ',
regex-group(3))"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:for-each>
</xsl:when>
</xsl:choose>
<xsl:text>)</xsl:text>
</xsl:template>
<xsl:template match="article/abstract">
<output>
<xsl:call-template name="production_dates"/>
</output>
</xsl:template>
</xsl:stylesheet>
Output
=======
<output>(Received 30 September 2008)</output>
But the desired output is:
(Received 30 September 2008; final version received 30 September 2008; final
version accepted 30 October 2008)
I've noticed that problem with my <xsl:choose><xsl:when> conditions in which
it does not reach to the next <xsl:when> conditions. And which are true in
this case. (If I remove <xsl:choose> all seems to work well).
Is there any problem in my defining <xsl:for-each
select="//production-dates/@receiveddate"> "select" attribute or there
anything else I am missing. I am using Altova XMLSpy XSLT 2.0.
Any suggestions in this regard will be highly appreciated.
Best,
Pankaj Chaturvedi
============================================================================
================
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--