xsl-list
[Top] [All Lists]

RE: Re: How to match a element + part of an immediate text sibling?

2004-01-13 23:17:58
I'm pretty new to XSL myself, so I will probably be corrected.  I am not
aware functionality that can select a specific word based on the order
it is within a node.  The only way I know to do that is with
substring-before and substring-after.

This HTML/XML:

<p> the quick
        <em>brown</em>
        fox jumps
</p>

Transformed with this Style Sheet:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:msxsl="urn:schemas-microsoft-com:xslt">

<xsl:template match="p">
        <html>
                <p>
                        <xsl:value-of select="concat(' ',
substring-before(substring-after(., ' '), ' '), ' ')"/>
                        <em>
                                <xsl:value-of
select="substring-before(substring-after(substring-after(., ' '), ' '),
em)"/>
                                <xsl:value-of select="concat(' ', em, '
')"/>
                                <xsl:value-of
select="substring-before(substring-after(., em), ' ')"/>
                        </em>
                        <xsl:value-of select="concat(' ',
substring-after(substring-after(., em), ' '))"/>
                </p>
        </html> 
</xsl:template>

</xsl:stylesheet>

Produces this HTML source code with MSXML:

<html xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<p> the <em>quick
         brown 
        fox</em> jumps
</p>
</html>




-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Chulsung Kim
Sent: Tuesday, January 13, 2004 11:15 PM
To: xsl-list
Subject: [xsl] Re: How to match a element + part of an immediate text
sibling?

Sorry for the newbie question. I did search the archive, but I guess I
just
didn't know what keywords to use.

Say you are doing an HTML-to-HTML transformation and you want to
transform:
<p> the quick <em>brown</em> fox jumps </p>to:
<p> the <em>quick brown fox</em> jumps </p>How would you match the <em>
element and the two words immediately surrounding it, so you can
rearrange
them in the template? Or would you match p[em] instead and then
rearrange
its children somehow?

Thanks,
Chulsung Kim


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list