[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: "Dhunta, Vikram \(GE, Corporate\)" <vikram.dhunta@xxxxxx>
Date: Thu, 7 Dec 2006 00:09:34 +0530
extract text xml node
If it's textual content, I agree.. We certainly want to continue with
<p>Hello, <b>World!</b></p>

But if it's data, and since you're using xml, you obviuosly intend to
imitate a real world hierarchy/structure, wouldn't the following seem
strange:
<hardware>
<screws>
This is the description of screws
<screw>
One
</screw>
</screws><screws>
This is a specification of screws
<screw>
Two
</screw>
</screws></hardware>

By orphaning that text without a node, you take away the (meta-)meaning
of the text. Doesn't that defeat the purpose of using xml to describe
data so it can be used by other readers, human and machine?

To me, it gives me the same uncomfortable feeling as someone doing the
following in html:
<table>
<tr><td>Hello</td></tr>whoa whats this text doin here,..just don't
belong!
<tr><td>World</td></tr>
</table>

Rgds

(btw I'm a newbie here, I like this list, and if such debates are
considered spam, please don't reply and let it die :) )

-----Original Message-----
From: Wendell Piez [mailto:wapiez@xxxxxxxxxxxxxxxx]
Sent: Wednesday, December 06, 2006 11:58 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  How to extract data from an element and not from its
children

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