XSLTGeneral 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 .
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 ?
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
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".
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