Ad:
 
Apr 24th, 2009
0

Embarrassing XSLT newbie question

Expand Post »
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, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  3.  
  4. <xsl:template match="/">
  5. <xsl:apply-templates select="html"/>
  6. </xsl:template>
  7.  
  8. <xsl:template match="html">
  9. <xsl:comment>
  10. <xsl:value-of select="' Entered html template '"/>
  11. </xsl:comment>
  12. </xsl:template>
  13. </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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nurdglaw is offline Offline
2 posts
since Apr 2009
Apr 24th, 2009
0

Re: Embarrassing XSLT newbie question

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, XSLT and XPATH Syntax (Toggle Plain Text)
  1.  
  2. <?xml version="1.0"?>
  3. <root>
  4. <data>Daniweb</data>
  5. </root>

first.xsl

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:output indent="yes" method="html"/>
  4. <xsl:template match="/">
  5. <html>
  6. <!--new root node in result.html -->
  7. <xsl:apply-templates select="root"/>
  8. <!--node in first.xml to changed -->
  9. </html>
  10. </xsl:template>
  11. <xsl:template match="root">
  12. <xsl:comment>
  13. <xsl:value-of select="' Entered html template '"/>
  14. </xsl:comment>
  15. <body>
  16. <div>
  17. <xsl:value-of select="data"/>
  18. </div>
  19. </body>
  20. </xsl:template>
  21. </xsl:stylesheet>


call to excute

xsltproc result.html first.xsl first.xml

result

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1.  
  2. <html>
  3. <!-- Entered html template -->
  4. <body>
  5. <div>Daniweb</div>
  6. </body>
  7. </html>

Greetings from Germany
Helmut Hagemann
Reputation Points: 14
Solved Threads: 4
Junior Poster in Training
xml_looser is offline Offline
57 posts
since Apr 2009
Apr 24th, 2009
0

Re: Embarrassing XSLT newbie question

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nurdglaw is offline Offline
2 posts
since Apr 2009
May 4th, 2009
0

Re: Embarrassing XSLT newbie question

For a site that is written in XSLT and you can download both the XSLT and XML.

http://www.jenitennison.com/xslt/

We generate all our pages out by xslt transform, unfortunately you just see the html rather than the xslt and xml.

RonaldDuncan
http://www.uk-plc.net
Reputation Points: 10
Solved Threads: 0
Newbie Poster
RonaldDuncan is offline Offline
8 posts
since May 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: XPath Substring question
Next Thread in XML, XSLT and XPATH Forum Timeline: xpath help needed by newbie....





About Us | Contact Us | Advertise | Acceptable Use Policy
Build Custom RSS Feed


Follow us on Twitter


© 2010 DaniWeb® LLC