473,403 Members | 2,183 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,403 software developers and data experts.

Parsing for double elements through xsl

Hi,

Sorry if this is the wrong group I'm posting to. We are using a CMS
which saves all files as .xml. We have an xslt file where we parse
all html tags. At the moment, the CMS sometimes puts in < br / <
br / to separate content instead of placing text in < p tags.

I'm trying to find any instance where a < br follows a < br >,
however for some reason I'm not getting the syntax quite correct. I'm
just starting out with xsl, so it could be a silly mistake, but I
can't find out a solution.

We use xsl v 1.0. The code that I've tried is:

<xsl:template match="br">

<xsl:choose>
<xsl:when test="preceding-sibling::br[1]"></xsl:when>
<xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise>
</xsl:choose>
</xsl:template>

I thought that the [1] is meant to get the immediately preceding
sibling. However it still finds instances where there is a single br.

Can someone help in regards to how to find an immediate preceding
sibling. An example of the code I'm using is:

Text< br />
Text< br />< br />
Text< br />< br />
Text< br />
Text.

It ignores the first < br instance in the first line (as expected),
but it then finds the last single < br instance in the 4th line.
Eventually I'm hoping to then move the text in < p tags (using
preceding-sibling::text()[1]/ following-sibling::text()[1]), but for
the moment I just want to single out the double br.

Regards,
Linda
Mar 16 '08 #1
5 2524
<xsl:when test="preceding-sibling::br[1]"></xsl:when>

This would select the nearest preceding-sibling element named "br", if
such exists.

You want to test if the nearest preceding-sibling element has the name
"br", and this is essentially different:

Use:

preceding-sibling::*[1][self::br]
Hope this helped.
Cheers,
Dimitre Novatchev

On Mar 16, 3:32*pm, Linda <madhatter....@gmail.comwrote:
Hi,

Sorry if this is the wrong group I'm posting to. *We are using a CMS
which saves all files as .xml. *We have an xslt file where we parse
all html tags. *At the moment, the CMS sometimes puts in < br / <
br / to separate content instead of placing text in < p tags.

I'm trying to find any instance where a < br follows a < br >,
however for some reason I'm not getting the syntax quite correct. *I'm
just starting out with xsl, so it could be a silly mistake, but I
can't find out a solution.

We use xsl v 1.0. *The code that I've tried is:

<xsl:template match="br">

* *<xsl:choose>
* * <xsl:when test="preceding-sibling::br[1]"></xsl:when>
* * <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise>
* </xsl:choose>
</xsl:template>

I thought that the [1] is meant to get the immediately preceding
sibling. *However it still finds instances where there is a single br.

Can someone help in regards to how to find an immediate preceding
sibling. *An example of the code I'm using is:

Text< br />
Text< br />< br />
Text< br />< br />
Text< br />
Text.

It ignores the first < br instance in the first line (as expected),
but it then finds the last single < br instance in the 4th line.
Eventually I'm hoping to then move the text in < p tags (using
preceding-sibling::text()[1]/ following-sibling::text()[1]), but for
the moment I just want to single out the double br.

Regards,
Linda
Mar 17 '08 #2
Thanks for that, I gave that a try, however in the test, it is still
finding any br, not just the immediate br. Should I be putting this
test within a for-each? or should I be trying to find if the
preceding sibling is text instead?

On Mar 17, 1:04 pm, dnovatc...@gmail.com wrote:
<xsl:when test="preceding-sibling::br[1]"></xsl:when>

This would select the nearest preceding-sibling element named "br", if
such exists.

You want to test if the nearest preceding-sibling element has the name
"br", and this is essentially different:

Use:

preceding-sibling::*[1][self::br]

Hope this helped.

Cheers,
Dimitre Novatchev
Mar 17 '08 #3
dn********@gmail.com wrote:
> <xsl:when test="preceding-sibling::br[1]"></xsl:when>

This would select the nearest preceding-sibling element named "br", if
such exists.

You want to test if the nearest preceding-sibling element has the name
"br", and this is essentially different:

Use:

preceding-sibling::*[1][self::br]
An alternative is preceding-sibling::*[1][local-name()='br']

However, when an XPath statement fails when expected to work (IMHE),
there is a namespace in effect somewhere :-) Check...
>I thought that the [1] is meant to get the immediately preceding
sibling.
Yes, but it's already qualified by the ::br, so your orginal statement
matched the closest preceding element called br (no matter how much
earlier it occurred among the siblings), not the immediately preceding
element. Testing for ::*[1] always finds the immediately preceding
element; you then test for the name.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Mar 17 '08 #4
Thanks for that, I gave that a try, however in the test, it is still
finding any br, not just the immediate br. Should I be putting this
Then it's highly likely you might have a default namespace defined and
in
scope.

Search for articles explaining this most FAQ for XPath expressions.

Cheers,
Dimitre Novatchev

"Linda" <ma***********@gmail.comwrote in message
news:993fdfa5-8024-4c51-96b9-
a2**********@k13g2000hse.googlegroups.com...
Thanks for that, I gave that a try, however in the test, it is still
finding any br, not just the immediate br. Should I be putting this
test within a for-each? or should I be trying to find if the
preceding sibling is text instead?

On Mar 17, 1:04 pm, dnovatc...@gmail.com wrote:
<xsl:when test="preceding-sibling::br[1]"></xsl:when>

This would select the nearest preceding-sibling element named "br", if
such exists.

You want to test if the nearest preceding-sibling element has the name
"br", and this is essentially different:

Use:

preceding-sibling::*[1][self::br]

Hope this helped.

Cheers,
Dimitre Novatchev
Mar 17 '08 #5
Thank you both for the explainations. I didn't think that it had been
defined elsewhere, but I'll let you know if I don't solve the
problem. I've at least got some good directions at what I can search
for now.

Linda
>
Then it's highly likely you might have a default namespace defined and
in
scope.

Search for articles explaining this most FAQ for XPath expressions.
Mar 17 '08 #6

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

Similar topics

16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
1
by: kaede | last post by:
Hi all, Given the following data format: { "(1,2), "(2.5, 3.5)", .... } I would like to define a vector<string> to stored this data: v = "(1,2)", v = "(2.5, 3.5"), .... and would like to...
8
by: Bob Davis | last post by:
In C# one can construct a string using the format method. for example string newstring = string.Format("CC%d-%s.%d-%s-% d",123,"aaaa",456,"bbb",789); The resulting newstring will be...
26
by: SL33PY | last post by:
Hi, I'm having a problem parsing strings (comming from a flat text input file) to doubles. the code: currentImportDetail.Result = CType(line.Substring(7, 8).Trim(" "), System.Double) What...
6
by: g_no_mail_please | last post by:
Python 2.3.5 seems to choke when trying to parse html files, because it doesn't realize that what's inside <!-- --> is a comment in HTML, even if this comment is inside <script> </script>,...
1
by: Martin Pöpping | last post by:
Hello, I´ve a problem with parsing a double value from an xml file. My code looks like this: int concept_id; double rank; XmlElement root = documentXMLString.DocumentElement; XmlNodeList...
3
by: Anup Daware | last post by:
Hi Group, I am facing a strange problem here: I am trying to read xml response from a servlet using XmlTextWriter. I am able to read the read half of the xml and suddenly an exception:...
0
by: =?Utf-8?B?VWxmIFRob3JzZW4=?= | last post by:
I use Visual Studio 2005 for a C-project using an external compiler, and came up with the idea that error parsing would be neat, i.e. enabling the functionality available for a "normal" build...
3
by: spittinfire | last post by:
-------------------------------------------------------------------------------- I am trying to correct the errors on an assignment that has already been graded because I have to now modify it and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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...

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.