logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: Using substring and gaining a <a href="...">...<a> from within: msg#00027

Subject: Re: Using substring and gaining a <a href="...">...<a> from within

At 2002-08-13 12:26 -0400, Wolfgang.Schreurs@xxxxxxxxxxx wrote:
I hope someone can help me with this...

I've got 2 files, 1 XML/1 XSL. Both files are used for creating a HTML file.

XSLT and XPath questions could be better posted to the following list:

  http://www.mulberrytech.com/xsl/xsl-list

since the list you've written to tends to focus on the FO vocabulary.

The XML file looks like this:

<portal_banner>
        <spotlight_text>bla bla <a href="http://www.apple.com";>apple</a>
bla</spotlight_text>
        <spotlight_image</spotlight_image>
        <spotlight_image_href></spotlight_image_href>
</portal_banner>

Within the XSL file I want to take the line 'spotlight_text' and break it up
in a text part and a hyperlink.
The text part should contain: 'bla bla apple bla'.

I want 'apple' to be a hyperlink to (in this case) the apple website.

Essentially, then, a copy of the <spotlight_text> element? I'm confused with your reference to "break it up...".

This
should be generated within the XSL file.

Not sure what you mean here.

I also want the total text input to
be limited to for example 60 chars.

Now *that* is going to be difficult for you to guarantee.

At the moment I got this in my XSL file:

<xsl:template name="substring_template">
        <xsl:variable name="right_text_string" select="spotlight_text"/>
        <xsl:value-of select="substring($right_text_string,0, 60)"/>
</xsl:template>

The value of an element node is the text characters only, none of the element nodes.

The problem is that substring() removes the '<a href="...">...</a>' tag, but
as far as I know I have to use substring to count the chars. After these
files are processed (by Xalan), everything I get is this:
'bla bla apple bla' without the hyperlink on apple.

Does someone have a solution to get this working?

You haven't yet learned that XSLT and XPath are used to manipulate node trees, not to manipulate markup. The markup on the way in becomes a node tree, and the node tree you create becomes markup on the way out, but while your stylesheet is functioning you are dealing only with nodes and never with tags. You will not be able to algorithmically measure the markup that will be input to or produced from your stylesheet.

If you post your desired output based on the above available input, then someone may be able to interpret what exactly you are looking for.

I hope this helps.

.......... Ken


--
Upcoming hands-on in-depth 3-days XSLT/XPath and/or 2-days XSL-FO:
-                               North America:  Sep 30-Oct  4,2002
-                               Japan:          Oct  7-Oct 11,2002

G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/f/
Box 266, Kars, Ontario CANADA K0A-2E0  +1(613)489-0999 (Fax:-0995)
ISBN 0-13-065196-6                       Definitive XSLT and XPath
ISBN 1-894049-08-X   Practical Transformation Using XSLT and XPath
ISBN 1-894049-07-1                Practical Formatting Using XSLFO
XSL/XML/DSSSL/SGML/OmniMark services, books (electronic, printed),
articles, training (instructor-live,Internet-live,web/CD,licensed)
Next public training:           2002-08-05,26,27,09-30,10-03,07,10




<Prev in Thread] Current Thread [Next in Thread>