[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Problems with mixed content and inline elements wh

Subject: RE: Problems with mixed content and inline elements when transforming XHTML into another XML format
From: Tony Kinnis <kinnist@xxxxxxxxx>
Date: Mon, 27 Feb 2006 02:11:08 -0800 (PST)
kinnis developers
I appreciate your response and the fact you leave something to be
figured out. Admittedly I am very new to XSLT (less than 2 weeks) and
have a lot to learn. This problem in particular was escaping me and, to
boot, frustrating me as I am running up against my deadline. However, I
have finally got it right (just this second) and I now have a greater
understanding of what I was missing. I had changed so many things over
time I had lost track of what I had and hadn't tried. Most of my
confusion was around the match and grouping functionality adn the thing
that finaly bit me in the end was missing the copy-of, which was
present in your sample. 

Anyway, thanks helping me to stretch my learning. I do have one
performance/maintainability question if you don't mind. I am wondering
about the is-inline method. In particular the "or" condition for
building the sequence of in-line elements. Is this the best way to
manage the list of included elements. I am wondering if it is a
performance issue. I am wondering if there is a better way to capture
the list of inline elements. Maybe in a global variable?

FYI - Here is the working and complete version of the script. It seems
so straight forward now. Thanks again.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
    xpath-default-namespace="http://www.w3.org/1999/xhtml"
    xmlns:f="http://localhost"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:my="http://localhost/markup.xsd">
    
    <xsl:output indent="yes" method="xml" encoding="UTF-8"
standalone="no"/>
    
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:for-each-group select="node()|@*"
group-adjacent="f:is-inline(.)">
                <xsl:choose>
                    <xsl:when test="current-grouping-key()">
                        <xsl:element name="my:textnode">
                            <xsl:copy-of select="current-group()"/>
                        </xsl:element>
                    </xsl:when>
                    <xsl:otherwise>   
                        <xsl:apply-templates select="current-group()"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:for-each-group>
        </xsl:copy>    
    </xsl:template>
    
    <xsl:function name="f:is-inline" as="xs:boolean">
        <xsl:param name="node" as="node()"/>
        <!-- 
        I am concerned about building this sequence in this way. Maybe
there is a better way.
        -->
        <xsl:sequence select="($node instance of text() and
normalize-space($node)) 
            or
$node[self::u|self::b|self::i|self::strong|self::span|self::em|self::br|self::img|self::font|self::a]"/>
    </xsl:function>
</xsl:stylesheet>



--- Michael Kay <mike@xxxxxxxxxxxx> wrote:

> > 
> > Sorry to keep asking about this problem but I am still having
> issues.
> > The change you mention below does remove the error but now it never
> > hits the block of code to wrap the elements in the textnode. It is
> > simply outputting the input verbatim. 
> 
> I'm afraid that when I reply to a question, I supply snippets of code
> that
> address the issue you're having, but don't attempt to supply a
> complete
> working solution: I leave that to you. Usually I reckon that this
> forces
> people to understand the solution rather than just transcribing it,
> which
> means they will learn more and have less need to return for further
> help...
> 
> Looking at your code, you're inside a template with match="/", so
> select="node()" is only going to select the outermost element, and
> grouping
> a single element is not very useful. You need to put this code in the
> template rule for the element that contains the nodes to be grouped.
> You may
> also need to apply it at more than one level, in which case the
> xsl:copy-of
> should be replaced by an xsl:apply-templates.
> 
> Michael Kay
> http://www.saxonica.com/
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.