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 February 4th, 2013, 09:39 AM
Authorized User
 
Join Date: Feb 2013
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT: a simple question

Hallo everyone,

I have this code line:

Code:
...
...
<xsl:value-of select="tag/childTag"/><xsl:text>"</xsl:text>
...
...
I would like to ask, what would happen, if in my xml file there is no element called tag or childTag? Would the processor just ignore the code line or will it output an error?

Another question:
I always thought that I have understood XSLT, but I am confused regarding these 2 terms:
1. XSL file
2. XSLT Style Sheet

Are they the same? Is a XSL file always a XSLT Style Sheet? Thank you for your help.

Regards,

Ratna
 
Old February 4th, 2013, 10:47 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If there is no child element matching tag, or grandchild matching childTag, then the select expression selects an empty sequence, the xsl:value-of instruction converts this result to an empty string, so the effect is to output an empty string, which in practice means the instruction does nothing.

The term "XSL" is best avoided, because different people use it to mean different things. Sometimes people use it as a synonym for XSLT, but not always; sometimes they mean XSL-FO, for example, and in Microsoft at one time it meant the Microsoft dialect of XSLT called WD-xsl.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old February 4th, 2013, 12:24 PM
Authorized User
 
Join Date: Feb 2013
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hallo Michael,

thanks for the help.

continuing the question regarding "what would it be, if...":

Code:
<xsl:for-each select="Tag"> 
       <xsl:value-of select="'1~'"/>
       <xsl:value-of select="Tag_1/Tag_1_1"/><xsl:text>"</xsl:text>     	
       <xsl:value-of select="Tag_2"/><xsl:text>"</xsl:text>
</xsl:for-each>
In the XML file, there is no tag "Tag", so for-each can not be processed. BUT, there are "Tag_1/Tag_1_1" and "Tag_2".
Will my Saxon Processor still output the value from "Tag_1_1" and "Tag_2"?

Last question:
What is the meaning of <xsl:value-of select="'1~'"/> ? Is it a constant?

Thank you for the help.

Regards,

Ratna
 
Old February 4th, 2013, 12:26 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If select="Tag" selects nothing, you are iterating over an empty sequence, so the body of the loop is executed zero times.

<xsl:value-of select="'1~'"/> outputs the string literal "1~" (it's easy enough to try it and see!)
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple XSLT Problem (HELP PLEASE) gaeawalker XSLT 2 October 10th, 2007 10:27 AM
simple XSLT apply-templates question fannus XSLT 7 March 27th, 2007 02:11 AM
simple XSLT question _thinking XSLT 4 January 24th, 2006 10:41 AM
simple xml / xslt example needed badgolfer ASP.NET 1.0 and 1.1 Basics 2 January 21st, 2005 02:10 AM
Simple question about XSLT bertcox XSLT 2 May 5th, 2004 09:31 AM





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