?
Solved

set/test flag to format XML using XSL

Posted on 2006-04-05
10
Medium Priority
?
689 Views
Last Modified: 2013-11-18
I am processing an XML document and need to have an opening and closing string displayed according to a value of one of the XML tags.  I first check if Value = Title and then multiple Msg's will follow and finally in the first instance where I have EndTitle, I would like to put some text. I was wondering how to do something like this.

<xsl:variable name = "Title" >Title</xsl:variable>

<xsl:for-each select="Msg">

<xsl:variable name = "Status" ><xsl:value-of select="Status" /></xsl:variable>

<xsl:if test="$Status = $Title">
OPEN TITLE<br/>
<xsl:value-of select="MessageID" /><br/>

NEED TO SET FLAG HERE TO

</xsl:if>

<xsl:if test="$Status = $CloseTitle">
<xsl:if test="FLAG IS SET?">   I need to do something like this
CLOSE TITLE<br/>
</xsl:if>
</xsl:if>


The XML looks like this:

<Msg>
      <MessageNb>1</MessageNb>
      <MessageID>Message1</MessageID>
      <Message>This is message 1</Message>
      <Status/>
</Msg>
0
Comment
Question by:pesst
  • 6
  • 3
9 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16380834
Hi pesst,

you can't set flags in XSLT,
so you need to deal with it using position() (to check the position in the for-each loop)
or with testing values in XPath

Cheers!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16380843
pesst,
> the first instance where I have EndTitle

I am not sure the actual question is completely clear
where do you have endTitle? is itr a string value of MessageID?

cheers
0
 
LVL 2

Author Comment

by:pesst
ID: 16380942
It's in Status.
so i set $Status, to the current content of the XML tag "Status".

I need to have: if Title was found in the loop and if EndTitle is found later in another Msg then put some text.

thanks
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16381067
pesst,

it could be something like this

<xsl:if test="$Status = $CloseTitle">
    <xsl:if test="preceding-sibling:Msg/Status = 'Title'">
    CLOSE TITLE<br/>
    </xsl:if>
</xsl:if>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16381080
pesst,

The inner xsl:if tests whether there is a previous Msg with a Statusvalue 'Title'
if that is not what you need, changing is pretty straightforward
always here to help

cheers
0
 
LVL 2

Author Comment

by:pesst
ID: 16381116
Does <xsl:if test="preceding-sibling:Msg/Status = 'Title'"> if the previous tag was  'Title' or does it also work if 10 Msg's back it was 'Title'?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16381332
it tries them all,
if you only need the previous one,
you need
<xsl:if test="preceding-sibling:Msg[1]/Status = 'Title'">
cheers
0
 
LVL 2

Author Comment

by:pesst
ID: 16381371
i think i will just change the XML to have a value of ClosedTitle and just check for that, instead of having formatting based on past tag values.
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 16381595
from the modelling point of view that would be better

you could easily group them like this though

OPEN-TITLE
<xsl:for-each select="Msg[(Status = 'Title) or (Status = 'EndTitle') or (preceding-sibling::Msg/Status = 'Title' and following-sibling::Msg/Status = 'EndTitle')]">
     <xsl:value-of select="MessageID" /><br/>
</xsl:for-each>
CLOSE-TITLE

this way you can even have XML tags instead of just strings before and after
the for-each selects the EndTitle, Title and all Msgs in between

This is how I would do it without changing the XML

cheers
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question