pesst
asked on
set/test flag to format XML using XSL
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</Messa geID>
<Message>This is message 1</Message>
<Status/>
</Msg>
<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</Messa
<Message>This is message 1</Message>
<Status/>
</Msg>
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
> 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
ASKER
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
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
pesst,
it could be something like this
<xsl:if test="$Status = $CloseTitle">
<xsl:if test="preceding-sibling:Ms g/Status = 'Title'">
CLOSE TITLE<br/>
</xsl:if>
</xsl:if>
it could be something like this
<xsl:if test="$Status = $CloseTitle">
<xsl:if test="preceding-sibling:Ms
CLOSE TITLE<br/>
</xsl:if>
</xsl:if>
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
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
ASKER
Does <xsl:if test="preceding-sibling:Ms g/Status = 'Title'"> if the previous tag was 'Title' or does it also work if 10 Msg's back it was 'Title'?
it tries them all,
if you only need the previous one,
you need
<xsl:if test="preceding-sibling:Ms g[1]/Statu s = 'Title'">
cheers
if you only need the previous one,
you need
<xsl:if test="preceding-sibling:Ms
cheers
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!