473,512 Members | 15,363 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strings of an xml element using XSL and XPath

AR
Hi,

How can I get strings separately which contain text nodes of a given
element using XSL and XPath?

For example,

<a>
aaa 111
<b>
bbb
<c>
ccc
</c>
BBB
</b>
AAA 222
</a>

For element <a> I need "aaa 111" and "AAA 222" separately.

Thanks in advance

Jul 20 '05 #1
2 1541


AR wrote:

How can I get strings separately which contain text nodes of a given
element using XSL and XPath?

For example,

<a>
aaa 111
<b>
bbb
<c>
ccc
</c>
BBB
</b>
AAA 222
</a>

For element <a> I need "aaa 111" and "AAA 222" separately.


/a/text()
selects those text nodes which are child nodes of the <a> element.
As for processing them seperately you can use xsl:for-each
select="/a/text()" or xsl:apply-templates select="/a/text()".

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
AR <ar********@yahoo.com> wrote:
Hi,

How can I get strings separately which contain text nodes of a given
element using XSL and XPath?

For example,

<a>
aaa 111
<b>
bbb
<c>
ccc
</c>
BBB
</b>
AAA 222
</a>

For element <a> I need "aaa 111" and "AAA 222" separately.

Thanks in advance


In Bash shell with Expat interface, you can do

start() # Usage: start tag att=value ...
{
case $1 in
a) out=(); i=0 ;;
*) i=$((i + 1)) ;;
esac
}
data() # Usage: data text
{
case ${XML_ELEMENT_STACK[1]} in
a) strcat out[i] "$*" ;;
esac
}
end() # Usage: end tag
{
case $1 in
a) declare -p out ;;
esac
}

xml -s start -d data -e end '<a>...</a>'
Basic idea is to collect contiguous text in the same array element.
out[0]='... aaa 111 ...'
out[2]='... AAA 222 ...'

If you want to strip whitespaces and re-index, then
out=( "${out[@]|.strip}" )
which gives you
out[0]='aaa 111'
out[1]='AAA 222'

--
William Park <op**********@yahoo.ca>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
http://home.eol.ca/~parkw/thinflash.html
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
15205
by: Daniel Frey | last post by:
Hello, I'd like to extract the name of an indirectly addressed element by subsequently using the childs position: 001 <a> 002 <b1/> 003 <b2/> 004 <b3/> 005 </a>
2
1781
by: dingbat | last post by:
Losing my marbles here (some sleep would help!) Why are the following XPath comparisons both returning false ? <xsl:value-of select="string('2005-09-22T12:43:23') &gt;...
4
9539
by: Viktor Jevdokimov | last post by:
Hello, I've got an XML file saved from DataSet. One table has datetime column (datatype - xs:dateTime). XML file fragment for example: <Root>...
5
1415
by: mavis | last post by:
the reference of the content of XML element In XSD, how can I specify the content of an element refers to the content of another element in an xml file? Thanks a lot!
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.