Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT - removing a tag from within text

Reply
Thread Tools

XSLT - removing a tag from within text

 
 
gwoodhouse@gmail.com
Guest
Posts: n/a
 
      06-17-2009
On Jun 17, 2:34*pm, Martin Honnen <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > Yeah, problem is none of that works.

>
> None of what?


<xsl:template match="span">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

would make a global change to the functionality of the XSLT (not that
this actually seems to do anything at all even if it did work)

All i want is a nice simple string/node change. On just one node. When
i tell it to. Everywhere else in the XSLT it's doing exactly as it
should, the only thing i need to change is outputting the end_time
field WITHOUT <span>.
 
Reply With Quote
 
 
 
 
Philippe Poulard
Guest
Posts: n/a
 
      06-17-2009
http://www.velocityreviews.com/forums/(E-Mail Removed) a écrit :
> On Jun 17, 2:34 pm, Martin Honnen <(E-Mail Removed)> wrote:
>> (E-Mail Removed) wrote:
>>> Yeah, problem is none of that works.

>> None of what?

>
> <xsl:template match="span">
> <xsl:copy>
> <xsl:apply-templates select="@* | node()"/>
> </xsl:copy>
> </xsl:template>
>
> would make a global change to the functionality of the XSLT (not that
> this actually seems to do anything at all even if it did work)
>
> All i want is a nice simple string/node change. On just one node. When
> i tell it to. Everywhere else in the XSLT it's doing exactly as it
> should, the only thing i need to change is outputting the end_time
> field WITHOUT <span>.


you don't have a <span> node, you just have a <span> text; just use
string manipulation functions such as substring-before() and
substring-after() that are available in xslt 1.0 for that purpose

something like this:

<xsl:template match='end_time'>
<xsl:value-of select="substring-before(.,'<span')"/>
<xsl:value-of
select="substring-before(substring-after(.,'>'),'</span>'"/>
<xsl:value-of select="substring-after(.,'</span>')"/>
</xsl:template>

very ugly

--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
 
Reply With Quote
 
 
 
 
gwoodhouse@gmail.com
Guest
Posts: n/a
 
      06-17-2009
> you don't have a <span> node, you just have a <span> text; just use
> string manipulation functions such as substring-before() and
> substring-after() that are available in xslt 1.0 for that purpose


If only it were that easy -

I get the error message:
Line #100; Column #57; org.xml.sax.SAXParseException: The value of
attribute "select" associated with an element type "xsl:value-of" must
not contain the '<' character.

and putting &lt; gives a stack overflow exception as it seems to make
the proccessor recurse continually.
 
Reply With Quote
 
Philippe Poulard
Guest
Posts: n/a
 
      06-17-2009
(E-Mail Removed) a écrit :
>> you don't have a <span> node, you just have a <span> text; just use
>> string manipulation functions such as substring-before() and
>> substring-after() that are available in xslt 1.0 for that purpose

>
> If only it were that easy -
>
> I get the error message:
> Line #100; Column #57; org.xml.sax.SAXParseException: The value of
> attribute "select" associated with an element type "xsl:value-of" must
> not contain the '<' character.


you're right, i forgot to escape it:

<xsl:template match='end_time'>
<xsl:value-of select="substring-before(.,'&lt;span')"/>
<xsl:value-of
select="substring-before(substring-after(.,'&gt;'),'&lt;/span&gt;'"/>
<xsl:value-of select="substring-after(.,'&lt;/span&gt;')"/>
</xsl:template>

>
> and putting &lt; gives a stack overflow exception as it seems to make
> the proccessor recurse continually.


this template doesn't recurse; check elsewhere how it is invoked

to make it run alone, change the template that matches the root:

<xsl:template match='/'>
<xsl:apply-templates select="//end_time"/>
</xsl:template>

after the last <xsl:value-of>, you also might find useful to add \n :
<xsl:text>&#xA;</xsl:text>

--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
 
Reply With Quote
 
Mayeul
Guest
Posts: n/a
 
      06-17-2009
(E-Mail Removed) wrote:
> So, basically, i want this:
>
> [snip]
>
> Yes it's in a CDATA tag but that doesn't seem to change anything at
> all.
>


Actually, it changes just about everything. By definition, there are no
elements in a CDATA tag. XSLT is mainly designed to operate with XPath
rules, not with raw text.

--
Mayeul
 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      06-17-2009
As others have said, that isn't "a tag in text" -- it's text which
happens to look like a tag. Your only option is string manipulation.
 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      06-17-2009
Note too that putting "tags" in text is generally Bad Practice unless
you really want the visible representation of a tag rather than an
actual element. If you're writing an XML/HTML tutorial, what you're
doing may make sense. If that isn't what you're doing, this is probably
not saying what you want it to say.
 
Reply With Quote
 
gwoodhouse@gmail.com
Guest
Posts: n/a
 
      06-18-2009
Dunno where you guys work but i'd love the choice of what data i
get

I'm sorry to say this, but again, using string manipulation just isn't
working.
Here's my code:
<xsl:template name="removeSpan">
<xslaram name="variable"/>
<xsl:if test="contains($variable, 'span')"><xsl:text>value:</
xsl:text></xsl:if>
<xsl:value-of select="substring-before($variable, 'span')"/>
<xsl:value-of select="substring-after($variable, 'hit&quot;')"/>
<xsl:text>jim</xsl:text><xsl:value-of select="$variable"/>
</xsl:template>

Here's the output:
jim01:
<span class="hit">
22
</span>
:45

As you can see it doesn't even like "span" ?! (i of course tried this
with &lt; and even < first)

Anyone see why this is going wrong?
 
Reply With Quote
 
gwoodhouse@gmail.com
Guest
Posts: n/a
 
      06-18-2009
i can however pull back:
01:<span class="hit">

if i try and do:
substring-before($variable, "22").
 
Reply With Quote
 
gwoodhouse@gmail.com
Guest
Posts: n/a
 
      06-18-2009
On Jun 18, 10:29*am, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> i can however pull back:
> 01:<span class="hit">
>
> if i try and do:
> substring-before($variable, "22").


Ahem, yes, found the problem. The output was going through a proccess
i was unaware of, converting [mkup][mkup] tags to <span class="hit"></
span>.

So, yeah er, problem solved. Reason i couldn't just manipulate the
string to get rid of <span> was that it wasn't there.

Yes, i deserve your scorn (and pity).

Thats a day i'll never get back again

Thanks for your help though i guess.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing tag + closing tag jwcarlton Perl Misc 12 09-26-2010 10:14 PM
Select text within a div tag by clicking on content of div tag or a button? visu Javascript 4 11-22-2006 06:25 AM
XSLT question: How to lookup another tag's children in XSLT yinglcs@gmail.com XML 18 10-03-2006 11:22 PM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
Select text within a div tag by clicking on content of div tag? M Wells Javascript 0 10-06-2004 11:04 AM



Advertisments