 |
| 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
|
|
|
|

July 27th, 2010, 11:37 AM
|
|
Registered User
|
|
Join Date: Jul 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
problem with xslt transformation
Hi,
I am new to XSLT transformations.. and was trying the following code...
Code:
<xsl:output method="html"/>
<xsl:template match="test">
<html>
<head>
<style type="text/css">
s1 { font-family: Arial; font-size: 12px }
</style>
</head>
<p style="s1">
This is
<xsl:value-of select="test-Name"/>
from
<xsl:value-of select="test-city"/>
</p>
</html>
</xsl:template>
</xsl:transform>
I am expecting the output to be...
This is XYZ (Value in Name) from TEXAS ( value in city)..
however i am getting ...
This is from.
Let me know how to fix the issue?
|
|

July 27th, 2010, 11:42 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
You haven't shown us what your input XML looks like, so we really couldn't say.
|
|

July 27th, 2010, 11:46 AM
|
|
Registered User
|
|
Join Date: Jul 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The input xml looks like this..
<asx:values>¶
<test>¶
<Name>Testn</Name>¶
<City>Texas</City>¶
</test>¶
</asx:values>¶
|
|

July 27th, 2010, 11:51 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
So you don't want "test-Name" you just want "Name".
|
|

July 27th, 2010, 11:53 AM
|
|
Registered User
|
|
Join Date: Jul 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by samjudson
So you don't want "test-Name" you just want "Name".
|
I want the output to be..
This is "Test" from 'Texas"
currently my output is This is from
|
|

July 27th, 2010, 12:03 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
There is no element in your XML called "test-Name". You have one called "test" and one called "Name".
You can refer to child elements in XPath by using the "/" character, e.g. select all "Name" elements who are children of a "test" element would be "test/Name".
However in your XSLT you are already inside the "test" element template, so you simply need to do <xsl:value-of select="Name"/> to get the value of the "Name" element.
|
|

July 27th, 2010, 12:03 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Which part of Sam's answer didn't you understand? Your element is called "Name", it is not called "test-Name", so you need to change
Code:
<xsl:value-of select="test-Name"/>
to
Code:
<xsl:value-of select="Name"/>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

July 27th, 2010, 12:47 PM
|
|
Registered User
|
|
Join Date: Jul 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by mhkay
Which part of Sam's answer didn't you understand? Your element is called "Name", it is not called "test-Name", so you need to change
Code:
<xsl:value-of select="test-Name"/>
to
Code:
<xsl:value-of select="Name"/>
|
thanks there...this solved the problem.
|
|

July 27th, 2010, 02:03 PM
|
|
Registered User
|
|
Join Date: Jul 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How do I specify fonts for output?
|
|

July 28th, 2010, 03:14 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
That is no an XSLT question - you want a basic tutorial on CSS.
But based on your incorrect example above you want to define the CSS style as ".s1" not "s1" and then apply it to the paragraph element as <p class="s1">
|
|
 |