473,320 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

[Q] XPath/XSL: how to get "position" of "embedded elem in mixed content?

hi there!

given
<!ELEMENT a (#PCDATA | x)*>
<!ELEMENT x (#PCDATA)>
how can I find out if x is "embedded" at the beginning
<a><x>xxx</x>aaa</a>
or at the end
<a>aaa<x>xxx</x></a>
or in the middle
<a>aaa<x>xxx</x>bbb</a>
of the content of element a?

what I need to do is to output x according to it's
"position" within a. examples:
<a><x>xxx</x>aaa</a> --> "xxx+aaa"
<a>aaa<x>xxx</x></a> --> "aaa+xxx"
<a>aaa<x>xxx</x>bbb</a> --> "aaa+xxx+bbb"

can any body help me with the two test clauses needed?
<xsl:template match="x">
<xsl:choose>
<xsl:when test="???">
<!-- x at start -->
<xsl:value-of select="."/>
<xsl:text>+</xsl:text>
</xsl:when>
<xsl:when test="???">
<!-- x at end -->
<xsl:text>+</xsl:text>
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
<!-- x in the middle -->
<xsl:text>+</xsl:text>
<xsl:value-of select="."/>
<xsl:text>+</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

thank you very much! andreas (ala_NO@SPAM_context.ch)
Jul 20 '05 #1
1 2582


nobody wrote:

given
<!ELEMENT a (#PCDATA | x)*>
<!ELEMENT x (#PCDATA)>
how can I find out if x is "embedded" at the beginning
<a><x>xxx</x>aaa</a>
or at the end
<a>aaa<x>xxx</x></a>
or in the middle
<a>aaa<x>xxx</x>bbb</a>
of the content of element a?

what I need to do is to output x according to it's
"position" within a. examples:
<a><x>xxx</x>aaa</a> --> "xxx+aaa"
<a>aaa<x>xxx</x></a> --> "aaa+xxx"
<a>aaa<x>xxx</x>bbb</a> --> "aaa+xxx+bbb"

can any body help me with the two test clauses needed?


Here is an XSLT 1.0 stylesheet

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="text" encoding="UTF-8" />

<xsl:template match="/">
<xsl:apply-templates select="root/a" />
</xsl:template>

<xsl:template match="a">
<xsl:apply-templates select="node()" mode="add" />
<xsl:text> </xsl:text>
</xsl:template>

<xsl:template match="x | text()" mode="add">
<xsl:choose>
<xsl:when test="position() &lt; last()">
<xsl:value-of select="." />
<xsl:text>+</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>

that transforms

<?xml version="1.0" encoding="UTF-8"?>
<root>
<a><x>xxx</x>aaa</a>
<a>aaa<x>xxx</x></a>
<a>aaa<x>xxx</x>bbb</a>
</root>

into the following text:

xxx+aaa
aaa+xxx
aaa+xxx+bbb

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

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

Similar topics

4
by: Ghyslaine Crespe | last post by:
Hello, In my script, the line document.getElementById(id).style.background-position = "-200px -500px"; fails ! So, how can I change the background-position value ?
7
by: Doc | last post by:
I've read in a couple of different places including the archives of this forum that html doesn't allow you to precisely dictate the position of an image, but I found this command (again in the...
8
by: Lian | last post by:
Hi all, It is a newbie's question about html tag "img". The attributes "title" and "alt" for "img" seems having the same function. So what is the main difference between them? Can i use them at...
10
by: Michael Strorm | last post by:
Hi! I've been having problems with a DTD. Having had the Sun XML validator reject a document, I put it through 'xmllint' for more information. 'Xmllint' noted a problem with the DTD itself;...
2
by: TadPole | last post by:
Hi all, My main problems are::::::::: 1. Set a value within a block container that can be used and changed by subsequent templates/block-containers/tables etc.. 2. get/determine/find the...
5
by: TPS | last post by:
When I set trace enable to true in my web.config file, the debug info does not display at the "bottom" of the page, it displays "under" all of my buttons, labels, grids etc. This behavior...
3
by: R. P. | last post by:
Subject: XSLT to transform a flat XML file into a structured text file I have an XML file that lists the PDF file segment names and titles of a larger document and looks something like this: ...
4
by: john | last post by:
Hi to All, I am new to html authoring, so sorry if my terminology is not correct or exact. I would like to position a footer div to the bottom of the browser window. As I research in the web...
1
by: vunet.us | last post by:
Mozilla reported the fix to this bug: https://bugzilla.mozilla.org/show_bug.cgi?id=167801. When input text field is located over div, the cursor cannot be seen unless special CSS properties are...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.