Hi,

I'm trying to delelop a stylesheet to add some tags to the top and bottom of HTML head and body nodes. So, I've started off with a stylesheet that looks like

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:template match="/">
    <xsl:apply-templates select="html"/>
  </xsl:template>
  
  <xsl:template match="html">
    <xsl:comment>
      <xsl:value-of select="' Entered html template '"/>
    </xsl:comment>
  </xsl:template>
</xsl:stylesheet>

which I apply to a random bit of HTML via xsltproc sample.xslt sample.html . The problem is that I don't get any output. I've flooded my code with various <xsl:comment> elements and as far as I can tell, my template for handling the root element is being entered, and that element has an html element as a child, yet when I <xsl:apply-templates select="html"/> , my <xsl:template match="html"/> desn't get executed. I am really confused.

I clearly have a blind spot - I've typed in the Hello, World example from chapter 2 of the O'Reilly XSLT book, and that behaves the same way as my own attempts - i.e. it doesn't work.

Of course, it could be that xsltproc doesn't work properly - I'm on Ubuntu 8.04 LTS - but a quick search on Google doesn't reveal dozens of other people saying the same sort of thing, so I think it's more likely that I'm being daft - again.

I'd _really_ appreciate a nudge in the right direction - ideally a gentle nudge :-)

Thanks,
Alan

here is to be found xslt parser

http://www.xmlsoft.org/XSLT/downloads.html

xsltproc is an alias or batch like
if parametres can be preset

xmllint.exe --xinclude --output %1 %2 %3

first.xml

<?xml version="1.0"?>
<root>
	<data>Daniweb</data>
</root>

first.xsl

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" method="html"/>
	<xsl:template match="/">
		<html>
               <!--new root node in result.html -->
			<xsl:apply-templates select="root"/>
                        <!--node in first.xml to changed -->
		</html>
	</xsl:template>
	<xsl:template match="root">
		<xsl:comment>
			<xsl:value-of select="' Entered html template '"/>
		</xsl:comment>
		<body>
			<div>
				<xsl:value-of select="data"/>
			</div>
		</body>
	</xsl:template>
</xsl:stylesheet>

call to excute

xsltproc result.html first.xsl first.xml

result

<html>
  <!-- Entered html template -->
  <body>
    <div>Daniweb</div>
  </body>
</html>

Greetings from Germany
Helmut Hagemann

Thanks for the reply. Heaven knows what I was doing wrong this morning, but I've given it another go and have got it working.

I had a problem because my input documents started with <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> rather than with <html> and with the attributes, my stylesheet wouldn't output anything.

I can work around this with a process improvement - I'm going to add the attributes in the stylesheet rather than requiring them to be in the input documents, but I'm curious to know what the problem is, and how I can match elements with the above attributes.

Thanks again,
Alan

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.