tough XSLT problem

B

Bloody Viking

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
 
?

=?ISO-8859-1?Q?Joachim_Wei=DF?=

Bloody said:
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
 
P

Peter Flynn

Bloody said:
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
 
B

Bloody Viking

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
 
P

Peter Flynn

Bloody said:
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
 
B

Bloody Viking

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
 
P

Peter Flynn

Bloody said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top