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 August 4th, 2006, 09:23 AM
Authorized User
 
Join Date: Jun 2006
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
 
Old August 4th, 2006, 09:42 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
 
Old August 4th, 2006, 09:46 AM
Authorized User
 
Join Date: Jun 2006
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

 
Old August 4th, 2006, 09:55 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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





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 04:11 AM





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