473,387 Members | 1,791 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.

tough XSLT problem

Namaste, Y'all.

Given an element A containing elements B,C,D,E,F, I need to create a
variable that gets the value of element C, conditionally followed by
the value of element D, only if the element following C is named 'X'.
How do I do this?

<xsl:template match="A">
<xsl:variable name="someText">
<xsl:value-of select="C">
<xsl:if <!-- YOUR CODE HERE -->

</xsl:variable>

<!-- more XSLT here -->
</xsl:template>

TIA,

Paul M Lieberman

Aug 23 '05 #1
6 1170
Bloody Viking schrieb:
Namaste, Y'all.
Namaste???

Given an element A containing elements B,C,D,E,F, I need to create a
variable that gets the value of element C, conditionally followed by
the value of element D, only if the element following C is named 'X'.
How do I do this?

<xsl:template match="A">
<xsl:variable name="someText">
<xsl:value-of select="C">
<xsl:if test="C = 'X'">

<xsl:value-of select="D">
</xsl:if>
....

Wasn't so tought then, or did I miss the question?
HIH

Jo
Aug 23 '05 #2
Bloody Viking wrote:
Namaste, Y'all.

Given an element A containing elements B,C,D,E,F, I need to create a
variable that gets the value of element C, conditionally followed by
the value of element D, only if the element following C is named 'X'.
This conflicts with your statement in the first sentence, which says that
A contains (B,C,D,E,F). No mention of an element named "X". Did you mean
"element following C has the value 'X'"?
How do I do this?

<xsl:template match="A">
<xsl:variable name="someText">
<xsl:value-of select="C">


This will do it for an element named X

<xsl:if test="name(C/following-sibling::*[1])='X'">
<xsl:value-of select="D"/>
</xsl:if>
</xsl:variable>
<!-- more XSLT here -->
</xsl:template>

This will do it for an element with the value X

<xsl:if test="C/following-sibling::*[1]='X'">
<xsl:value-of select="D"/>
</xsl:if>
</xsl:variable>
<!-- more XSLT here -->
</xsl:template>

However, as you said that A contains only B,C,D,E,F, the element following C
can only be named D, so maybe you meant "if the value of element D is 'X'",
in which case:

<xsl:if test="D='X'">
<xsl:text>D</xsl:text>
</xsl:if>
</xsl:variable>
<!-- more XSLT here -->
</xsl:template>

///Peter

Aug 23 '05 #3
Pardon me. My example wasn't clear. A contains any number of elements,
which may be named with any letter, and it may contain multiple
instances of an element named X (X may contain any text). So, one
element A may have:
<A><B/><C>C-text</C><X>X-text</X><D/><E/><X>X-text</X></A>

another instance of A may be:

<A><B/><C>C-text</C><D/><E/><X>X-text</X></A>

The variable created must have the text of element C. If the element
immediately following C is named X (as in the first example), the
variable should then have a space followed by the text in X:

C-text X-text

- Paul

Aug 23 '05 #4
Bloody Viking wrote:
Pardon me. My example wasn't clear. A contains any number of elements,
which may be named with any letter, and it may contain multiple
instances of an element named X (X may contain any text). So, one
element A may have:
<A><B/><C>C-text</C><X>X-text</X><D/><E/><X>X-text</X></A>

another instance of A may be:

<A><B/><C>C-text</C><D/><E/><X>X-text</X></A>
OK, gottit, thanks.
The variable created must have the text of element C. If the element
immediately following C is named X (as in the first example), the
variable should then have a space followed by the text in X:

C-text X-text


OK, then my first example will do (adding the space):

<xsl:template match="A">
<xsl:variable name="someText">
<xsl:value-of select="C">
<xsl:text> </xsl:text>
<xsl:if test="name(C/following-sibling::*[1])='X'">
<xsl:value-of select="D"/>
</xsl:if>
</xsl:variable>
<!-- more XSLT here -->
</xsl:template>

///Peter

Aug 23 '05 #5
Excellent! I'm sure that will do the trick!

I hadn't known that I could prefix a following-sibling expression with
the name of an element.

Thanks, Peter.

- Paul

Aug 23 '05 #6
Bloody Viking wrote:
Excellent! I'm sure that will do the trick!

I hadn't known that I could prefix a following-sibling expression with
the name of an element.


Actually it's not really prefixing, just specifying a location ladder down
to the element you want, starting at C. More like suffixing C with
following-sibling :-)

///Peter

Aug 24 '05 #7

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

Similar topics

1
by: Ola Natvig | last post by:
Hi all I'm working with a long running, threaded server which serves HTTP requests with content which are passed through a XSLT processor. The XSLT processor I'm using is the Pyana processor. ...
6
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a...
6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
0
by: Mike | last post by:
I'm generating an XSLT document programatically in VB.Net. I'm then trying to apply that XSLT against a cXML document to generate my own internally developed XML document. I'm using RichTextBox...
4
by: Moogy | last post by:
I'm pulling my hair out here. First, I'm new to XML, so that doesn't help, but none of this makes any sense to me. All I'm trying to do is take a simple source XML file and translate it with an...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
3
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as...
3
by: RC | last post by:
Let's say: if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { // Now I got an XML object here var xmlDocument = XMLHttpRequestObject.responseXML; // next I have...
0
by: ManWithNoName | last post by:
The following question is related to this thread: XSLT, document() function, filename, read non-standard/English characters (like µ) I have a XML file with a non-English character in its name...
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: 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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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.