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 July 27th, 2010, 11:37 AM
Registered User
 
Join Date: Jul 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
 
Old July 27th, 2010, 11:42 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You haven't shown us what your input XML looks like, so we really couldn't say.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old July 27th, 2010, 11:46 AM
Registered User
 
Join Date: Jul 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The input xml looks like this..


<asx:values>¶
<test>¶
<Name>Testn</Name>¶
<City>Texas</City>¶
</test>¶
</asx:values>¶
 
Old July 27th, 2010, 11:51 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

So you don't want "test-Name" you just want "Name".
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old July 27th, 2010, 11:53 AM
Registered User
 
Join Date: Jul 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by samjudson View Post
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
 
Old July 27th, 2010, 12:03 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old July 27th, 2010, 12:03 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old July 27th, 2010, 12:47 PM
Registered User
 
Join Date: Jul 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by mhkay View Post
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.
 
Old July 27th, 2010, 02:03 PM
Registered User
 
Join Date: Jul 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How do I specify fonts for output?
 
Old July 28th, 2010, 03:14 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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">
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
help on xslt transformation li72 XSLT 2 March 4th, 2008 10:14 AM
Help on XSLT transformation li72 XSLT 2 February 22nd, 2008 12:33 PM
help with xslt transformation li72 XSLT 6 November 19th, 2007 01:51 PM
XSLT transformation yengzhai XSLT 1 April 21st, 2005 05:51 AM
XSLT transformation causes ^M reddygaru XSLT 2 December 16th, 2003 10:41 AM





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