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 April 7th, 2007, 11:10 AM
Registered User
 
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Almost there but cannot get it right

Hi,
   I have been trying to get this thing to work correctly but it either strips the whole content or puts the content but including the parent element (Panel). Basically what I need is that everything that is between Panel elements be passed exactly as it is (including markup).

So far either I get nothing from between Panels. or the whole content including Panel elements (need them out) or the text with all the markup stripped off.

Here is the source XML. The purpose is that with the XSLT All the content (including markup) IN BETWEEN Panel tags get passed. The Transform is appended here as well.

Hopefull somebody lets me see the light :)

========================
Here is the source document:

<?xml version="1.0" encoding="utf-8"?>
<Panels>
    <Panel>
        This is plain text
    </Panel>
    <Panel>
        <h3>Heading</h3>
        <p>and paragraph</p>
    </Panel>
</Panels>
==========================
And here is the transform so far:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="Panel">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tbody>
        <tr>
            <td class="paperBox">
                <xsl:copy-of select="current()"/>
            </td>
            <td class="ppboxRightBg" valign="top"><div class="ppboxRightTop"></div></td>
        </tr>
        <tr>
            <td colspan="2" class="ppboxBottomBg">
                <div class="ppboxBottomLeft"></div>
                <div class="ppboxBottomGray"></div>
                <div class="ppboxBottomGrad"></div>
                <div class="ppboxBottomRight"></div>
            </td>
        </tr>
    </tbody>
      </table>

    </xsl:template>

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

 
Old April 7th, 2007, 11:23 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

I am not sure I understand, but if you want to include the XML markup on output you can do:

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

 
Old April 7th, 2007, 11:33 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You haven't made yourself very clear, but perhaps you want to change

<xsl:copy-of select="current()"/>

which copies the Panel element, to

<xsl:copy-of select="child::node()"/>

which only copies its children.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 7th, 2007, 12:34 PM
Registered User
 
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks to both of you for the quick reply guys. I will have to go with MH Kay's answer which does exactly what I wanted. Had been some time since I last XSLT'ed and just couldn't get the thing doing what I wanted.


 
Old April 7th, 2007, 12:52 PM
Registered User
 
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

However one thing I never got right makes me wonder about the eficacy of XSLT. For example, if I have some none ASCII characters such as ó or ñ then the XSLT will crap out with an error message. If I replace them by entities such as &ntilde; and &oacute; then same problem. Is there a way to effectively make a transform robust enough that it would not crap out with those characters used in non-English languages?

 
Old April 7th, 2007, 07:05 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It would help if you were less colloquial in your choice of language. Tell us what exactly what you are doing and exactly how it is failing and we might be able to tell us what you are doing wrong. (In most cases the error message means exactly what it says, and if you don't understand it, then we can help you, but only if you show us the error message).

Happy Easter.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference









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