Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General 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
 
Old June 4th, 2009, 06:47 PM
Authorized User
 
Join Date: Apr 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default maintain the format in the output xml

Hi all,
in my below xsl . I have a tag like this below

<Sample>
<xsl:value-of select="(./Date)"/>
</Sample>

sometimes the finalDate field will have null value so the output xml is coming like
<Sample/>

Eventhough it is correct my client application is expecting like this
<Sample>
</Sample>

Can you pls help to modify my xsl so that I can have output like the below
<Sample>
</Sample>

Thanks in advance
 
Old June 4th, 2009, 06:54 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You'll need to do

Code:
<xsl:choose>
  <xsl:when test="Date">
     <xsl:value-of select="Date"/>
  </xsl:when>
  <xsl:otherwise>
     <xsl:text> </xsl:text>
  </xsl:otherwise>
</xsl:choose>
That's assuming XSLT 1.0. In 2.0 you can do
Code:
<xsl:value-of select="(Date, ' ')[1]"/>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old June 4th, 2009, 07:31 PM
Authorized User
 
Join Date: Apr 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot Kay . I tried the exact code but it did not work. I modified the code a little , it is working , but pls let me know whether what I have done is correct. I have used the below code.

Code:
 
<xsl:variable name="varSample" select="string((./varSample[1]))"></xsl:variable>
                        <Sample>
                           <xsl:choose>
                              <xsl:when test="string-length($varSample) > 0">
                                 <xsl:value-of select="(./Sample[1])"></xsl:value-of>
                              </xsl:when>
                              <xsl:otherwise>
                                 <xsl:text></xsl:text>
                              </xsl:otherwise>
                           </xsl:choose>
                        </Sample>
 
Old June 5th, 2009, 04:25 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You missed the space within the xsl:text element. An empty xsl:text element does nothing. I put a space there because you showed it in your desired output. I wasn't sure if you really wanted the space, or if you just wanted a start tag followed immediately by an end tag. If that's what you wanted (a start tag followed immediately by an end tag) then you can't achieve that - it's precisely equivalent to an empty tag (that is, <a></a> is exactly equivalent to <a/>), and if your receiving application accepts one and not the other, then that's a serious bug and you should fix it. The whole point about XML is the benefit of sticking to the standard, and there's no point in using XML unless your applications follow the standard, you might as well invent your own private markup language.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old June 5th, 2009, 10:44 AM
Authorized User
 
Join Date: Apr 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for explaing to me Kay. The problem is with the client application and we have raised this issue with them. Thanks once again





Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert/Output HTML to MHT format takwirira ASP.NET 2.0 Professional 0 February 23rd, 2009 08:19 AM
Creating XML doc ; writing string(xml format) into KamalRaturi XML 5 May 28th, 2008 05:51 AM
Content Mgmt. System to Maintain XML Data? kwilliams XML 0 May 6th, 2008 09:09 AM
Output XML Hadware .NET Framework 1.x 0 December 28th, 2005 09:55 PM
XML output prashantnair XML 6 June 9th, 2004 12:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.