xsl-list
[Top] [All Lists]

[xsl] Re: [xml-dev] XSLT Stylesheet test for special character

2009-01-22 08:31:46
At 2009-01-22 14:08 +0100, nico wrote:
Hello,

( 4 ) <xsl:value-of select="ns:strong"/>

does not do anything, except dumping the text content of ns:strong into the output. If you want to use that value, you have to set a variable with that, like :
<xsl:variable name="value" select="ns:strong/text()"/>

Not when that element has embedded content.  If you had:

   <ns:strong>this has <ns:em>emphasized text</ns:em> in it</ns:strong>

Then in XSLT

  <xsl:variable name="value" select="ns:strong/text()"/>

... is a node set variable with two text nodes "this has " and " in it".

Whereas

  <xsl:variable name="value" select="ns:strong"/>

... is a node set variable with one element node, whose text value is "this has emphasized text in it".

In all of my production work I have very very rarely ever had to directly address text nodes. Perhaps in a match pattern for nuanced matching, but I can't think of where I've used it in a value-of.

I tell my students "if you think you need to address a text node directly, think again because you may but you probably don't".

Try that with a XSLT debugger,

I've found with my customers and my students a danger in trying to interpret language behaviour from the perspective of a debugger: you only understand what you see based on the data sample you are working with. This doesn't explain the proper behaviour of language constructs.

see what you have in that variable, and then you can try something like :

<xsl:when test="contains($value, 'Firstname:')">

Be aware that if you do text() when current node is <ns:p> (you previously did <xsl:for-each select="/ns:html/ns:body/ns:div[(_at_)id='content']/ns:p">), you obtain the concatenation of recursively applying text() on all the children node of <ns:p> so you will have white spaces, content of markup <a>, etc...

False. The XPath expression "text()" when the current node is an element returns only the text node immediate children of the element, not the concatenated string value of the element.

Use a debugger ! (Oxygen has a great one)

A debugger is great, but only when you know what you are doing in the language ... it can be very misleading to use a debugger as a learning tool.

I hope these comments are considered constructive ... I didn't want a reader of the archive to be mislead.

. . . . . . . . . . Ken

--
Upcoming XSLT/XSL-FO, UBL and code list hands-on training classes:
:  Sydney, AU 2009-01/02; Brussels, BE 2009-03; Prague, CZ 2009-03
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • [xsl] Re: [xml-dev] XSLT Stylesheet test for special character, G. Ken Holman <=