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

RE: How to extract data from an element and not from i

Subject: RE: How to extract data from an element and not from its children
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 06 Dec 2006 11:58:13 -0500
RE:  How to extract data from an element and not from i
At 11:42 AM 12/6/2006, it was written:
Would you be better off by re-designing your xml as:
<text>
<content>This text is some test </content>
<content><emph>text</emph></content>
<content>.</content>
</text>

Somehow that text within the xml doesn't seem correct - it looks
orphaned, but I guess the experts can answer that..

Would one really want to have


<p><content>I have a paragraph, which contains </content><inline>inline markup</inline><content> inside it.</content></p>

On the contrary, XML's capability of modeling mixed content (the technical term for this sort of thing) is one of its greatest strengths.

As for the question, in XSLT terms, the XML markup:

<text>This text is some test <emph>text</emph>.</text>

is parsed into a model that looks like this:

element 'text'
  text node (value: 'This text is some test ')
  element 'emph'
    text node (value: 'text')
  text node (value: '.')

These XML document structures are traversed and queried in XSLT using not functions, but XPath expressions (XPath includes a function library, but also more).

In this case, given the 'text' element as context, the XPath expression "text()", short for "child::text()", will return both the text node children of the element (its first and third children). If you want the value of only the first of these, you can write "text()[1]". In XPath 1.0, simply "text()" will often get you that result, but since the rules have changed in XPath 2.0 it's perhaps best to learn not to rely on that.

How you use that depends on why you need the expression, which wasn't given in the question.

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

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-2011 All Rights Reserved.