Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get TicketDate from xml document 1

Status
Not open for further replies.

momo2000

Programmer
Jan 2, 2015
63
US
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

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

XML
XML:
<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="[URL unfurl="true"]http://tsgweb.com"[/URL] xmlns:IXML="[URL unfurl="true"]http://tsgweb.com"[/URL] xmlns:CMCodeQueryHelper="urn:CMCodeQueryHelper" PackageID="IXML Case Notification Test" MessageID="67084253" xmlns="">
<Case Op="E" InternalID="1617090499" ID="12125626" xmlns:user="[URL unfurl="true"]http://tylertechnologies.com">[/URL]
    <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="[URL unfurl="true"]http://tylertechnologies.com">[/URL]
    <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="[URL unfurl="true"]http://tylertechnologies.com">[/URL]
    <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: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>
 
This is a good place, I think, to use [tt]<xsl:key>[/tt] and the associated key() function.

Small reference: and Tutorial:
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
 
here is an example of using keys on your data:

Code:
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
<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:
<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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top