473,387 Members | 1,569 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,387 software developers and data experts.

Test on child elements - alternative?

Hello there

I've inherited some code, which looks like this:

<!-- recreate the element (with its namespace) -->
<xsl:element name="{local-name()}" namespace="{namespace-uri()}">

<!-- if it has children... -->
<xsl:if test=".//">
<!-- process the children -->
<xsl:apply-templates/>
</xsl:if>
<!-- if it does not have children... -->
<xsl:if test="not(.//)">
<!-- recreate its value -->
<xsl:value-of select="."/>
</xsl:if>
</xsl:element>

Which seems to be a long winded <xsl:copy of> method - but the
important part is that the test for children -> ".//" no longer works
with a newer version of xerces - i'm getting an error along the lines
of "a location step was expected after the //".

So the question is - is there another more correct way of testing for
children right down the node tree, i'm sure there is but i'm stumped
with my limited xslt experience.

Thanks in advance

Jun 27 '06 #1
3 1116
Replace ".//" with ".//*" and see if that helps.

\/\//\ Wim

Phil Jenkins wrote:
Hello there

I've inherited some code, which looks like this:

<!-- recreate the element (with its namespace) -->
<xsl:element name="{local-name()}" namespace="{namespace-uri()}">

<!-- if it has children... -->
<xsl:if test=".//">
<!-- process the children -->
<xsl:apply-templates/>
</xsl:if>
<!-- if it does not have children... -->
<xsl:if test="not(.//)">
<!-- recreate its value -->
<xsl:value-of select="."/>
</xsl:if>
</xsl:element>

Which seems to be a long winded <xsl:copy of> method - but the
important part is that the test for children -> ".//" no longer works
with a newer version of xerces - i'm getting an error along the lines
of "a location step was expected after the //".

So the question is - is there another more correct way of testing for
children right down the node tree, i'm sure there is but i'm stumped
with my limited xslt experience.

Thanks in advance


Jun 27 '06 #2
Hi Wim

Thanks for that - the error has stopped, but the template match doesn't
exhibit the same behaviour - anything that isn't a child element (i.e
text) is being replicated twice.

<element>Text</element> would come out as TextText.

Thanks for your help so far

Jun 27 '06 #3
For anyone interested - the error was due to upgrading from Xalan 2.3
to 2.7, where the XPath '//' statement has been replaced with the more
correct /descendant-or-self::node()

Jun 27 '06 #4

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

Similar topics

4
by: Doug Estep | last post by:
Below is a sample of my XML… <MetaData> <Table name="mytable"> <PrimaryKey name="pk"><Column name="mycolumn"/></PrimaryKey> </Table> </MetaData> <Sequencer> <Table name="mytable">
4
by: n_o_s_p_a__m | last post by:
My xml doc has many <title></title> and <title> in it, meaning the nodes have no content (although some do). How can I test for this? I tried title (doesn't work) I tried //title (doesn't work)...
19
by: Thomas Mlynarczyk | last post by:
Hello, The following gives different results in IE and "Non-IE" browsers: <div style="background-color: green; width: 200px"> <div style="margin-top: 20px; background-color: red"> Hello...
3
by: Sam | last post by:
I wrote a script to show or hide items in an HTML list (<ul id="stuff">) depending on whether a list-item's CLASS attribute matches an input string (catString), which is chosen from a SELECT menu....
0
by: Kathy Burke | last post by:
Hi again. I finally figured out WHAT I need, but not much of a clue how to do it. I'm new to datagrids and I'm using a document-like xml structure versus a database-like structure. I think I need...
2
by: Gabriele Bertolucci | last post by:
In VBA I would like to test if an OptionButton is chiled of an OptionGroup. I wrote this test OptionButton.Parent.ControlType = acOptionGroup It's all OK if this test is executed on an...
1
by: adamredwards | last post by:
I have a page with some form elements that are dynamically generated. They are inserted into the dom by first cloning a node, changing the values like name, and then inserted with insertBefore(). ...
4
by: Keith Patrick | last post by:
I'm trying to parse some XML via IXPathNavigable, handling elements, text, and attributes with the same code but without having a switch (node.NodeType). However, if I look at a parent element in...
7
by: dweeti | last post by:
Hi, I am trying to display the child element in the DOM, while hiding the parent using JS and CSS, however I cannot find a way to do this. So for example: <body> <div id="Parent"> <div...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
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
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
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...

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.