INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How do I get TicketDate from xml document

How do I get TicketDate from xml document

(OP)
I would like to get TicketDate where ChargeID is the same as CitationCharge/ChargeID. There could be several ChargeIDs with several CitationIDs. So I will need to check where ChargeID matches CitationCharge/ChargeID so that I get the right TicketDate. The TicketDate is the same as xsl element <nc:Date>

Desired output should look like this

CODE --> xml

<nc:ActivityDate>2014-03-26</nc:ActivityDate> 

XML

CODE --> xml

<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:IXML="http://tsgweb.com" xmlns:CMCodeQueryHelper="urn:CMCodeQueryHelper" PackageID="IXML Case Notification Test" MessageID="67084253" xmlns="">
<Case Op="E" InternalID="1617090499" ID="12125626" xmlns:user="http://tylertechnologies.com">
    <Charge ID="10906090" PartyID="16765959" InternalChargeID="1616713754" InternalPartyID="1614667066" xmlns:reslib="urn:reslib">
        <ChargeOffenseDate>04/13/2015</ChargeOffenseDate>
            <ChargeHistory ChargeHistoryID="42933438" Stage="Case Filing" FilingSequence="1" CurrentCharge="true" InternalOffenseHistoryID="1637029057">
            <ChargeNumber>1</ChargeNumber>
        </ChargeHistory>
        <ChargeHistory ChargeHistoryID="42933437" Stage="Citation Issued" CitationEventSequence="1" InternalOffenseHistoryID="1637029056">
            <ChargeNumber>1</ChargeNumber>
        </ChargeHistory>
        <Deleted>false</Deleted>
    </Charge>
    <Charge ID="10906091" PartyID="16765959" InternalChargeID="1616713755" InternalPartyID="1614667066" xmlns:reslib="urn:reslib">
        <ChargeOffenseDate>04/13/2015</ChargeOffenseDate>
        <ChargeHistory ChargeHistoryID="42933440" Stage="Case Filing" FilingSequence="1" CurrentCharge="true" InternalOffenseHistoryID="1637029059">
            <ChargeNumber>2</ChargeNumber>
        </ChargeHistory>
        <ChargeHistory ChargeHistoryID="42933439" Stage="Citation Issued" CitationEventSequence="1" InternalOffenseHistoryID="1637029058">
            <ChargeNumber>2</ChargeNumber>
        </ChargeHistory>
    </Charge>
</Case>
<Citation ID="5385330" xmlns:user="http://tylertechnologies.com">
    <CitationNumber>12345</CitationNumber>
    <OffenseDate>04/13/2015</OffenseDate>
    <TicketDate>04/13/2015</TicketDate>
    <CitationCharge>
        <ChargeID>10906090</ChargeID>
        <ChargeHistoryID>42933437</ChargeHistoryID>
        <ChargeNumber>1</ChargeNumber>
        <SequenceNumber>1</SequenceNumber>
    </CitationCharge>
</Citation>
<Citation ID="5385331" xmlns:user="http://tylertechnologies.com">
    <CitationNumber>54321</CitationNumber>
    <OffenseDate>04/13/2015</OffenseDate>
    <TicketDate>04/13/2015</TicketDate>
    <CitationCharge>
        <ChargeID>10906091</ChargeID>
        <ChargeHistoryID>42933439</ChargeHistoryID>
        <ChargeNumber>2</ChargeNumber>
        <SequenceNumber>1</SequenceNumber>
    </CitationCharge>
</Citation>
</Integration> 

xsl

CODE --> xsl

<xsl:template name="ChargeDetails">
<ext:Citation>
    <nc:AvtivityDate> 
        <xsl:if test="Charge[@ID=current()/../CitationCharge/ChargeID]">
        <nc:Date>
            <xsl:value-of select="mscef:formatDate(string(/Integration/Citation/TicketDate))"/>
        </nc:Date>
    </xsl:if>
    </nc:AvtivityDate>
</ext:Citation>
</xsl:template> 

RE: How do I get TicketDate from xml document

This is a good place, I think, to use <xsl:key> and the associated key() function.

Small reference: http://www.w3schools.com/xsl/el_key.asp and http://www.w3schools.com/xsl/func_key.asp
Tutorial: https://www.webucator.com/tutorial/learn-xslt/work...

In general, you declare a key to provide a means to reference nodes by a value. In this case, one node contains a value, and you want to find anther node that is associated with that same value. You declare a key for the nodes you want to look up, and use the key() function to find a nodeset that has the value you desire. Notice I said nodeset; a key value may be associated with more than one node. There is nothing wrong with using concat(), for example, when declaring a key value; doing so may help you get a unique key value by combining two or more values. Another possibility might be to use XPath predicates after the key() function (remember it is returning a nodeset) to further filter down to the node you want.

Using keys will edge you a little closer to using more fully the declarative side of XSLT.

Have a look at the reference and tutorial material, give it a try, and see what you can come up with. Ask questions. Happy to help someone having to dig through LegalXML. Just this last week, I used keys to help find all the references to a particular document in a civil filing. Some of the LegalXML structures are so intertwined, using keys is about the only way to keep yourself from becoming intertwined - like a pretzel.banghead

Tom Morrison
Hill Country Software

RE: How do I get TicketDate from xml document

here is an example of using keys on your data:

CODE --> XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>

<xsl:key match="Integration/Citation" use="CitationCharge/ChargeID"  name="CitationByChargeID"/>
  
<xsl:template match="/">
<root>
	<xsl:apply-templates select="Integration/Case/Charge"/>
</root>	
</xsl:template>

<xsl:template match="Charge">
<Citation>
    <AvtivityDate> 
        <Date forID="{@ID}">
            <xsl:value-of select="key('CitationByChargeID',@ID)/TicketDate"/>
        </Date>
        <CitationNumber	 forID="{@ID}">
            <xsl:value-of select="key('CitationByChargeID',@ID)/CitationNumber"/>
        </CitationNumber>
    </AvtivityDate>
</Citation>
</xsl:template> 
</xsl:stylesheet> 

CODE --> output

<root>
  <Citation>
    <AvtivityDate>
      <Date forID="10906090">04/13/2015</Date>
      <CitationNumber forID="10906090">12345</CitationNumber>
    </AvtivityDate>
  </Citation>
  <Citation>
    <AvtivityDate>
      <Date forID="10906091">04/13/2015</Date>
      <CitationNumber forID="10906091">54321</CitationNumber>
    </AvtivityDate>
  </Citation>
</root> 

Tom Morrison
Hill Country Software

RE: How do I get TicketDate from xml document

(OP)
Thanks Tom Morrison for your help.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close