Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 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
  #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...
  #2 (permalink)  
Old March 20th, 2008, 10:50 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 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>
  #3 (permalink)  
Old March 20th, 2008, 10:54 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
  #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 ....

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


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 09:19 AM





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