[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: <xsl:call-template> XSLT 2.0

Subject: RE: <xsl:call-template> XSLT 2.0
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 20 Nov 2008 08:58:16 -0000
RE:  <xsl:call-template> XSLT 2.0
In xsl:choose, the branches are mutially exclusive - only one will be
executed. I think you need to replace

<xsl:choose>
  <xsl:when test="A">X</xsl:when>
  <xsl:when test="B">Y</xsl:when>
  <xsl:when test="C">Z</xsl:when>
</xsl:choose>

by

  <xsl:if test="A">X</xsl:when>
  <xsl:if test="B">Y</xsl:when>
  <xsl:if test="C">Z</xsl:when> 

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Pankaj Chaturvedi [mailto:pankaj.chaturvedi@xxxxxxxxx] 
> Sent: 20 November 2008 08:36
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  <xsl:call-template> XSLT 2.0
> 
> 
> 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[@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[@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[@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
> 
> ==============================================================
> ==============
> ================

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.