Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 20th, 2008, 10:44 AM
Authorized User
 
Join Date: Mar 2008
Location: Denver, CO, USA.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default I can't figure this out.

I can't figure out how to create new xml elements to hold values of
another xml documents elements with XSLT. When I choose the output method of xml none of the < or > entities get converted to < >. So should I change the output method to "text" and just open by declaring the xml document myself? I'm sure there is some simple solution here that I just can't find a referencing example of.

Heres what my newb thoughts are composed of right now:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:output method="xml"/>

  <xsl:template match="/Root">
    &lt;NEWXMLELEMENT &gt;
      <xsl:value-of select="."/>
    &lt;/NEWXMLELEMENT&gt;
  </xsl:template>

</xsl:stylesheet>
I really want to know how to do this with XSLT properly and not have to revert to my old java methods...
Reply With Quote
  #2 (permalink)  
Old March 20th, 2008, 10:50 AM
Friend of Wrox
Points: 6,408, Level: 34
Points: 6,408, Level: 34 Points: 6,408, Level: 34 Points: 6,408, Level: 34
Activity: 14%
Activity: 14% Activity: 14% Activity: 14%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,190
Thanks: 0
Thanked 235 Times in 234 Posts
Default

I don't understand what you want to achieve.
You might want to post a sample of your input and then a sample of the output you want to create with your stylesheet.
Generally if you want to create elements with your stylesheet then you have two options, literal result elements e.g.
Code:
<xsl:template match="foo">
  <bar>
    <xsl:apply-templates/>
  </bar>
</xsl:template>
and constructing elements with xsl:element e.g.
Code:
<xsl:template match="foo">
  <xsl:element name="bar">
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>
Reply With Quote
  #3 (permalink)  
Old March 20th, 2008, 10:54 AM
mhkay's Avatar
Wrox Author
Points: 17,576, Level: 57
Points: 17,576, Level: 57 Points: 17,576, Level: 57 Points: 17,576, Level: 57
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,802
Thanks: 0
Thanked 260 Times in 255 Posts
Default

The way to create a new element is like this:

  <xsl:template match="/Root">
    <NEWXMLELEMENT>
      <xsl:value-of select="."/>
    </NEWXMLELEMENT>
  </xsl:template>

You need to understand a very basic concept in XSLT: a stylesheet doesn't generate a file containing lexical markup, it generates a tree containing nodes, which is then passed to a serializer to be serialized. The NEWXMLELEMENT element node in this stylesheet gets copied to create a NEWXMLELEMENT node in your result tree, and the serializer takes this element node and produces the angle bracket markup. If you try to generate markup (start and end tags) by hand, it becomes the content of a text node, which the serializer processes by escaping any special characters it finds.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #4 (permalink)  
Old March 20th, 2008, 11:11 AM
Authorized User
 
Join Date: Mar 2008
Location: Denver, CO, USA.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, I don't doubt I sound incredibly confused to every experienced xslt programmer trust me it sucks to be down here at this level of xslt.

What I'm saying is that there is some kind of conflict between your first example and my xslt processor. It genererates a error when I try to compile that using <xsl:output method="xml"/>

I'm here at work right now in a Federal building and so the computer security is outrageous and I don't have the Xalan installed here to tell you exactly the error, but I'm working on it ....

Reply With Quote
  #5 (permalink)  
Old March 20th, 2008, 11:13 AM
Authorized User
 
Join Date: Mar 2008
Location: Denver, CO, USA.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

mhkay & martin, thank you for expalining this to me. If you only knew how much I value ur input guys.... thanks.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chap 2 Figure 2-9 Prda2r3x BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 4 May 1st, 2007 10:39 AM
Help! - Can't Figure Out FaxCOMEXLib hugh@kmcnetwork.com VB How-To 0 May 10th, 2005 09:13 PM
Figure 4-7 on p. 64 clm3cv BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 27th, 2005 08:19 AM



All times are GMT -4. The time now is 12:58 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.