Page 1 of 1

How do I concatenate HearingDate and StartTime?

Posted: Tue Aug 12, 2014 7:51 pm
by winkimjr2
How do I get this result:
<ext:HearingDateTime>07/21/2014 8:30 AM</ext:HearingDateTime>
I have xml that have two StartTime and a HearingDate. The two StartTime are the same but one is near the top and the other one is a child of CourtSessionBlock.
The first StartTime is not always there which means sometimes the only available StartTime is the child of CourtSessionBlock.
For this reason, I need to first check if there is StartTime near the top of xml document. If it is there, I will use that StartTime concatenated with HearingDate. Otherwise if it's not there or when the only StartTime is the child of CourtSessionBlock, I will use that one. I have tried using <xsl:if> and <xsl:choose> but I am not getting anything displayed for the <ext:HearingDateTime/>. Please help.
Here is my xml code:

Code: Select all

<Setting ID="21613643" InternalSettingID="1622304543" Date="07/21/2014">
<HearingDate>07/21/2014</HearingDate>
<StartTime>8:30 AM</StartTime>
<EndTime>9:30 AM</EndTime>
<CourtSessionBlock InternalCourtSessionBlockID="1614615037">
<StartTime>8:30 AM</StartTime>
<EndTime>9:30 AM</EndTime>
</CourtSessionBlock>
<TimestampCreate>07/15/2014 09:27:49:607</TimestampCreate>
</Setting>
Here is my xslt code that is not displaying anything

Code: Select all

<ext:HearingDateTime>
<xsl:choose>
<xsl:when test="/Integration/Case/Setting/StartTime[1]">
<xsl:value-of select="StartTime"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="/Integration/Case/Hearing/Setting/CourtSessionBlock/StartTime"/>
</xsl:otherwise>
</xsl:choose>
</ext:HearingDateTime>

Re: How do I concatenate HearingDate and StartTime?

Posted: Wed Aug 13, 2014 8:31 am
by Radu
Hi,

In an XSLT stylesheet an xsl:when element does not change the context of the current matched element to be the one in the test attribute expression.

So your XSLT code should be something like:

Code: Select all

                <xsl:when test="/Integration/Case/Setting/StartTime[1]">
<xsl:value-of select="/Integration/Case/Setting/StartTime[1]"/>
</xsl:when>
Please consider posting XSLT-specific questions on the XSLT list:

http://www.mulberrytech.com/xsl/xsl-list/

Regards,
Radu