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 May 4th, 2006, 04:49 AM
Authorized User
 
Join Date: Jun 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rajatake
Default Doubt in XPATH synax in <xsl:apply-templates >

I am newbie to XSLT.

I am having one XML document which root element have five attributes.

for example
<root xmlns="org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="" id="root" value="1">.
I have to convert this to another XML document . I m using XSLT for this and I am using Xpath in the "xsl:apply-templates select=" statement.

My .xsl statement is as follows.

<xsl:apply-templates select="root/document/firstnode"/>

The above .xsl statement is not working. If i remove the attributes from the root element, the above statement is working fine.

I don't know why its not working. I have tried lot of possibilities with select="root[@*]/document/firstnode" ,
select="root[0]/document/firstnode". But couldn't make it out.

Please help me.

One more doubt:

I am using stylesheet reference in the XML file like <?xml-stylesheet href="stylesheet.xsl" type="text/xsl"?>.
This statement is missing in the output XML file. What i have to do for this?

Thanks and Regards,
N.Raja



 
Old May 4th, 2006, 05:16 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Suggest you read up on namespaces:

http://www.dpawson.co.uk/xsl/sect2/N5536.html

especially numbers 13 and 23.



--

Joe (Microsoft MVP - XML)
 
Old May 4th, 2006, 05:45 AM
Authorized User
 
Join Date: Jun 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rajatake
Default

I got the answer for my first question

the answer is

root[1]/document/firstnode.

I m not clear of the second one. Please help me. My i/p XML file is having the stylesheet reference and my output file is missing that reference.

<?xml-stylesheet href="stylesheet.xsl" type="text/xsl"?>.
it should come to the next line to <?xml version="1.0" encoding="utf-8"?>

 
Old May 4th, 2006, 06:30 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You need to understand that XPath expressions work on a representation of the XML document called the XPath Data Model. In this model:

* namespaces are not attributes (so your root element has 3 attributes, not 5)

* the <?xml-stylesheet?> ends up as a processing-instruction node. If you want to copy processing instructions, you need to write a template rule for them:

<xsl:template match="processing-instruction()">
  <xsl:copy/>
</xsl:template>

* the XML declaration is not represented by a node in the data model at all. The serializer looks after the job of creating a correct XML declaration in the output document.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
embedded <xsl:element> into <xsl:with-param> petergoodman XSLT 2 July 9th, 2008 06:36 AM
Performance for <xsl:import> and <xsl:include> vikkiefd XSLT 2 April 16th, 2008 08:06 AM
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
differnce between xsl:apply-templates and xsl:call chandu.mca007 XSLT 2 June 12th, 2007 04:12 AM
doubt in using <xsl:template> rajatake XSLT 5 December 15th, 2006 08:09 AM





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