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 August 4th, 2006, 09:23 AM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default omit-xml-declaration

Hi,

i'd like to know how to avoid the xml declaration in the output file. seems that omit-xml-declaration="yes" doesn't work :

Code:
<xsl:stylesheet
    xmlns:simulink=""
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">

  <xsl:output
    method="text"
    indent="no"
    omit-xml-declaration="yes"
    name="SIGNAL"/>

  <xsl:strip-space elements="*" />

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="simulink:Model|simulink:Library">
    <xsl:variable name="model_name" select="concat(property[@name='Name']/@value,'.SIG')" />
    <xsl:result-document href="{$model_name}" formalism="SIGNAL">
    ¬†¬†<xsl:apply-templates />
    </xsl:result-document>
  </xsl:template>
the declaration appears in the dest file.
another pb : when i put the code of simulink:Model or Library in the / element, seems like it doesn't see the elements 'property'. My source looks like this :

Code:
<?xml version="1.0" encoding="iso-8859-1"?>

<simulink:Model xmlns:simulink="">
  <property name="Name" value="modele" />
  <property name="Version" value="3.00" />
  <property name="SimParamPage" value="Solver" />
  <property name="SampleTimeColors" value="on" />
  <property name="InvariantConstants" value="off" />
  ....
why do i have to write a rule for simulink:Model in addition to the '/' rule ?

Thanks
Reply With Quote
  #2 (permalink)  
Old August 4th, 2006, 09:42 AM
mhkay's Avatar
Wrox Author
Points: 17,731, Level: 57
Points: 17,731, Level: 57 Points: 17,731, Level: 57 Points: 17,731, Level: 57
Activity: 63%
Activity: 63% Activity: 63% Activity: 63%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,833
Thanks: 0
Thanked 266 Times in 261 Posts
Default

Try omit-xml-declaration="yes" if you want to omit the XML declaration.

XPath expressions within the body of a template rule are relative to the node matched by the template rule. So the simple path "property" will select nothing unless the context node is the parent of the property element. Match="/" selects the document node, whose only child in your example is the simulink:Model element. In fact, property won't select anything even if the context node is simulink:Model - you have to say simulink:property, because that's the namespace it's in.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old August 4th, 2006, 09:46 AM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok thank you. But omit-xml-declaration works with libxslt but not with saxon ...
i thought that '/' select the root node, which i consider here as being "simulink:Model".

Thanks

Reply With Quote
  #4 (permalink)  
Old August 4th, 2006, 09:55 AM
mhkay's Avatar
Wrox Author
Points: 17,731, Level: 57
Points: 17,731, Level: 57 Points: 17,731, Level: 57 Points: 17,731, Level: 57
Activity: 63%
Activity: 63% Activity: 63% Activity: 63%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,833
Thanks: 0
Thanked 266 Times in 261 Posts
Default

Actually, you will never get an XML declaration with method="text", so something odd is going on here. But with method="xml", earlier releases of Saxon ignore omit-xml-declaration if you specify an encoding such as iso-8859-1, on the theory that a document in that encoding needs an XML declaration to make it well-formed XML.

"/" selects what XPath 2.0 calls the document node, which XPath 1.0 calls the root node. This is not the same as the outermost element, it is the parent of the outermost element. A very fundamental distinction.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
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
I need to omit the duplicate values when displayin ppakala XSLT 1 June 24th, 2008 06:13 PM
xml declaration not displayed zsheema XSLT 10 May 15th, 2008 04:36 AM
xml declaration chroniclemaster1 XML 0 September 20th, 2007 02:00 PM
Omit xmlns Pankaj C XSLT 3 July 31st, 2007 10:18 AM
Create XML Doc with Stylesheet Declaration rodmcleay General .NET 1 November 15th, 2004 03:11 AM



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


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