473,810 Members | 3,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPath - How to query for <dd> elements ?

Imagine the XHTML "definition list" structure

<dl>
<dt>A</dt>
<dd>a</dd>

<dt>B</dt>
<dd>b1</dd>
<dd>b2</dd>

<dt>C</dt>

<dt>D</dt>
[ ...]
</dl>
Given the element containing "A" as the context node, how can I retrieve
the elements for "a", similarly "B" for "b1,b2" etc. ?

Using ./preceding-sibling::* [1] [self::dd]
I can retrieve the elements for "A" ("a") and "C" (an empty set)
However I can't see any way to get "b1" & "b2", just the first "b1"
Thanks for any advice

May 3 '06 #1
3 3592
The simple-but-ugly way is to explicitly scan through the following
siblings until you hit the next <dt> or run out, using a recursive named
template.

Personally, I'd try to convince whoever was authoring the input document
to abandon the HTML markup on input (even if that's what you generate on
output) and use something with more structure to it, such as:

<deflist>
<entry><term>.. .</term><def>....</def><def>....</def></entry>
</deflist>

Then it's trivial; the definitions are the <def> children of the
<term>'s parent.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
May 3 '06 #2
Use
following-sibling::dd[preceding-sibling::dt[1]=current()]
get the following dd element whose first preceding dt is the surrent dt
element.
For instance the folllowing stylesheet
<?xml version="1.0" encoding="UTF-8"?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="/">
<result>
<xsl:apply-templates select="//dt"/>
</result>
</xsl:template>

<xsl:template match="dt">
<for value="{.}">
<xsl:for-each

select="followi ng-sibling::dd[preceding-sibling::dt[1]=current()]">
<got value="{.}"/>
</xsl:for-each>
</for>
</xsl:template>
</xsl:stylesheet>

will give you

<?xml version="1.0" encoding="utf-8"?>
<result>
<for value="A">
<got value="a"/>
</for>
<for value="B">
<got value="b1"/>
<got value="b2"/>
</for>
<for value="C"/>
<for value="D"/>
</result>

Note that the above assumes no namespace for the source elements, if
you use the XHTML namespace then you need to qualify the name tests
with the appropriate prefix, that is instead of dd for instance you
should have xhtml:dd and declare the XHTML namespace mapped to xhtml
prefix.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

May 4 '06 #3
George Bina wrote:
following-sibling::dd[preceding-sibling::dt[1]=current()]
get the following dd element whose first preceding dt is the current dt
element.


.... Yep, that should work, and it's certainly more compact.

Performance of this vs. other solutions is going to depend on the exact
characteristics of your XSLT processor, and so is hard to predict
reliably. I'm not sure whether the one I've been using would recognize
the optimization opportunities in that expression or not; I should check.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
May 4 '06 #4

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

Similar topics

6
3907
by: The Plankmeister | last post by:
Hi.. I'm trying to achieve a newline effect within a <dt> block, but am having problems. Here is the basic code: <dl> <dt> <a href="admin_menu.html" class="small">Click here to modify the
9
6846
by: Akseli Mäki | last post by:
Hi, the subject say quite a lot. I have about the following code(4.01 transitional): <p>blaa blaa blaa <ul> <li><a href="foo.html">foo</a></li> <li><a href="bar.html">bar</a></li> </ul>
2
5313
by: AES/newspost | last post by:
In a markup like <dd> <br> some other stuff <br> </dd> the first break seems to add a blank line before the other stuff, but the second doesn't add a blank line after the other stuff. The same seems to hold for <dt>. Is this a universal rule, or does it apply to many other HTML constructs? Is there some logical reason for it?
4
7845
by: Andre Majorel | last post by:
I'm trying to make a compact <dl> class à la troff .TP where you have Term Definition of the term. Longer Term Definition of the longer term. i.e. if the <dt> text is shorter than the margin-left, the <dd> is on the same line. Otherwise, the <dd> goes on the next line.
1
1554
by: enrico sabbadin | last post by:
hi, while playing with the SAML specs I found that one must insert a node like this if the call succeded <status xmlns:z=mynamspace" ... <z:statuscode result="z:Sucess"/> ... How do I set up an XPATH filter that veriffies if the call succeed ? .. I mean i cannot hardcode z:Success since another one could pass me out a doc like this
13
6850
by: onetitfemme | last post by:
I think browsers do it pretty much by default. How can you avoid that? It just doesn't look right/pretty for short definitions and also how can you not indent the whole <dd> so that in stead of looking like this: <code> _ _ _ term: def def def def def def ... _ _ _ _ _ _ def def def def def def ... </code>
13
2281
by: Mark | last post by:
Dear folks, In Javascript, is it possible to get all id names within, say, a <div></divpair? Like the array of "document.images", I mean. The reason I ask, is that I have a calender whose <td></tdtable elements, within a given <div></div>, all have a class type, one of which is "today" (to highlight it). Once the calender is drawn, the Javascript has ended. And since Javascript has no known (to me) method of storing variables in say,...
11
1992
by: trackside | last post by:
I'm using the great dd.dragdrop Library for many parts of the page, including loading in a user selected image via the "swapImage()" function. var imgRe = /^.+\.(jpg|jpeg|gif|png)$/i; function swapMe(pathField, previewName) { var path = pathField.value; if (path.search(imgRe) != -1) {
4
4593
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet reservation of available resources (laptops, beamers, etc). The MySql database queries are already in place, as is the ASP administration panel. The frontend that users will see however, still needs some work. I'm really close, but since I'm no...
0
9722
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10124
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6882
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4334
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 we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.