I have edited this question included a xml with the nodes to be used for the output and also the xslt I am using.
我编辑了这个问题包括一个xml,其中包含用于输出的节点以及我正在使用的xslt。
The output should include the following:
输出应包括以下内容:
ChargeNumber
StatuteCode
StatuteCode/@Word
Degree
ChargeOffenseDate
LocationofViolation
Here is what is required:
这是必需的:
For each unique ChargeID evaluate the ChargeHistory records. If, Stage=”Disposition Event” is found verify the number of DispositionEventSequence. If only “1” populate Charge Information, otherwise use the highest DispositionEventSequence to populate.
对于每个唯一的ChargeID,评估ChargeHistory记录。如果找到Stage =“Disposition Event”,则验证DispositionEventSequence的数量。如果只有“1”填充Charge Information,否则使用最高的DispositionEventSequence来填充。
If no Stage=”Disposition Event” is found look for Stage=”Case Filing” to populate. If only “1” populate Charge information, otherwise use the highest Case Filing Filing Sequence to populate.
如果找不到Stage =“Disposition Event”,则查找Stage =“Case Filing”以填充。如果只有“1”填充Charge信息,否则使用最高的Case Filing Filing Sequence来填充。
XML Code
<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="67078058" xmlns="">
<Case InternalID="1616807927" ID="11747370" xmlns:user="http://tylertechnologies.com">
<Charge ID="10547226" PartyID="16580814" CurrSentenceID="155092098" InternalChargeID="1616447618" InternalPartyID="1614482843" xmlns:reslib="urn:reslib">
<ChargeOffenseDate>03/26/2014</ChargeOffenseDate>
<ChargeHistory ChargeHistoryID="41490828" Stage="Case Filing" FilingSequence="1" InternalOffenseHistoryID="1635954993">
<ChargeNumber>1</ChargeNumber>
<ChargeOffenseDate deprecated="true">03/26/2014</ChargeOffenseDate>
<Statute>
<StatuteDescription>Traffic Regulations - Failure to obey traffic control device</StatuteDescription>
<StatuteCode Word="169064a" InternalCodeID="66247">Traffic Regulations - Failure to obey traffic control device</StatuteCode>
<Degree Word="PMD">Petty Misdemeanor</Degree>
</Statute>
<Additional>
<LocationOfViolation>Hwy 15 & Century Ave</LocationOfViolation>
</Additional>
</ChargeHistory>
<ChargeHistory ChargeHistoryID="41490828" Stage="Case Filing" FilingSequence="2" InternalOffenseHistoryID="1635954993">
<ChargeNumber>2</ChargeNumber>
<ChargeOffenseDate deprecated="true">03/26/2014</ChargeOffenseDate>
<Statute>
<StatuteDescription>Testing Case Filling 2</StatuteDescription>
<StatuteCode Word="169064a" InternalCodeID="66247">Testing Case Filing 2</StatuteCode>
<Degree Word="PMD">Petty Misdemeanor</Degree>
</Statute>
<Additional>
<LocationOfViolation>Hwy 15 & Century Ave</LocationOfViolation>
</Additional>
</ChargeHistory>
<ChargeHistory ChargeHistoryID="41858685" Stage="Disposition Event" DispositionEventSequence="1" CurrentCharge="true" InternalOffenseHistoryID="1636250409">
<ChargeNumber>10</ChargeNumber>
<ChargeOffenseDate deprecated="true">03/26/2014</ChargeOffenseDate>
<Statute>
<StatuteDescription>Traffic Regulations - Failure to obey traffic control device</StatuteDescription>
<StatuteCode Word="169064a" InternalCodeID="66247">Traffic Regulations - Failure to obey traffic control device</StatuteCode>
<Degree Word="PMD">Petty Misdemeanor</Degree>
</Statute>
<Additional>
<LocationOfViolation>Hwy 15 & Century Ave</LocationOfViolation>
</Additional>
</ChargeHistory>
<ChargeHistory ChargeHistoryID="41858685" Stage="Disposition Event" DispositionEventSequence="2" CurrentCharge="true" InternalOffenseHistoryID="1636250409">
<ChargeNumber>2</ChargeNumber>
<ChargeOffenseDate deprecated="true">03/26/2014</ChargeOffenseDate>
<Statute>
<StatuteDescription>Testing second disposition number 2</StatuteDescription>
<Degree Word="PMD">Petty Misdemeanor</Degree>
</Statute>
<Additional>
<LocationOfViolation>Hwy 15 & Century Ave</LocationOfViolation>
</Additional>
</ChargeHistory>
</Charge>
</Case>
</Integration>
I need to modify my xslt code but I am not sure how.
我需要修改我的xslt代码,但我不知道如何。
XSLT Code
<xsl:template name="Charge">
<ext:Charge>
<xsl:choose>
<xsl:when test="(count(ChargeHistory[@Stage='Disposition Event']))>0">
<xsl:for-each select="ChargeHistory[@Stage='Disposition Event']">
<xsl:sort select="position()" order="descending"/>
<j:ChargeSequenceID>
<xsl:value-of select="ChargeNumber"/>
</j:ChargeSequenceID>
<j:ChargeStatute>
<j:StatuteDescriptionText>
<xsl:value-of select="Statute/StatuteCode"/>
</j:StatuteDescriptionText>
<j:StatuteText>
<xsl:value-of select="Statute/StatuteCode/@Word"/>
</j:StatuteText>
</j:ChargeStatute>
<j:ChargeSeverityDescriptionText>
<xsl:value-of select="Statute/Degree"/>
</j:ChargeSeverityDescriptionText>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:when test="(count(ChargeHistory[@Stage='Case Filing']))>0">
<xsl:for-each select="ChargeHistory[@Stage=Case Filing']">
<xsl:sort select="position()" order="descending"/>
<j:ChargeSequenceID>
<xsl:value-of select="ChargeNumber"/>
</j:ChargeSequenceID>
<j:ChargeStatute>
<j:StatuteDescriptionText>
<xsl:value-of select="Statute/StatuteCode"/>
</j:StatuteDescriptionText>
<j:StatuteText>
<xsl:value-of select="Statute/StatuteCode/@Word"/>
</j:StatuteText>
</j:ChargeStatute>
<j:ChargeSeverityDescriptionText>
<xsl:value-of select="Statute/Degree"/>
</j:ChargeSeverityDescriptionText>
</xsl:for-each>
</xsl:when>
</xsl:otherwise>
</xsl:choose>
</ext:Charge>
</xsl:template>
1 个解决方案
#1
0
To obtain data from the ChargeHistory
with the highest DispositionEventSequence
value, sort the ChargeHistory
nodes by their DispositionEventSequence
value. Then take the data from the first (or last, depending on the sort order) node of the resulting set.
要从具有最高DispositionEventSequence值的ChargeHistory获取数据,请按其DispositionEventSequence值对ChargeHistory节点进行排序。然后从结果集的第一个(或最后一个,取决于排序顺序)节点获取数据。
Here's a minimized example:
这是一个最小化的例子:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/Integration">
<output>
<xsl:apply-templates select="Case/Charge"/>
</output>
</xsl:template>
<xsl:template match="Charge">
<Charge>
<xsl:for-each select="ChargeHistory[@Stage='Disposition Event']">
<xsl:sort select="@DispositionEventSequence" data-type="number" order="descending"/>
<xsl:if test="position()=1">
<ChargeNumber>
<xsl:value-of select="ChargeNumber"/>
</ChargeNumber>
<StatuteCode>
<xsl:value-of select="Statute/StatuteCode"/>
</StatuteCode>
<!-- get more data as needed -->
</xsl:if>
</xsl:for-each>
</Charge>
</xsl:template>
</xsl:stylesheet>
Edit:
In response to:
回应:
If, Stage=”Disposition Event” is found verify the number of DispositionEventSequence. If only “1” populate Charge Information, otherwise use the highest DispositionEventSequence to populate.
如果找到Stage =“Disposition Event”,则验证DispositionEventSequence的数量。如果只有“1”填充Charge Information,否则使用最高的DispositionEventSequence来填充。
If no Stage=”Disposition Event” is found look for Stage=”Case Filing” to populate. If only “1” populate Charge information, otherwise use the highest Case Filing Filing Sequence to populate.
如果找不到Stage =“Disposition Event”,则查找Stage =“Case Filing”以填充。如果只有“1”填充Charge信息,否则使用最高的Case Filing Filing Sequence来填充。
I believe this translates to: sort the records by Stage (Disposition Event
first), then by their respective Sequence number:
我相信这转化为:按Stage(首先是Disposition Event)排序记录,然后按各自的序号排序:
<xsl:template match="Charge">
<Charge>
<xsl:for-each select="ChargeHistory[@Stage='Disposition Event' or @Stage='Case Filing']">
<xsl:sort select="number(@Stage='Disposition Event')" data-type="number" order="descending"/>
<xsl:sort select="@FilingSequence" data-type="number" order="descending"/>
<xsl:sort select="@DispositionEventSequence" data-type="number" order="descending"/>
<xsl:if test="position()=1">
<ChargeNumber>
<xsl:value-of select="ChargeNumber"/>
</ChargeNumber>
<StatuteCode>
<xsl:value-of select="Statute/StatuteCode"/>
</StatuteCode>
<!-- get more data as needed -->
</xsl:if>
</xsl:for-each>
</Charge>
</xsl:template>
#1
0
To obtain data from the ChargeHistory
with the highest DispositionEventSequence
value, sort the ChargeHistory
nodes by their DispositionEventSequence
value. Then take the data from the first (or last, depending on the sort order) node of the resulting set.
要从具有最高DispositionEventSequence值的ChargeHistory获取数据,请按其DispositionEventSequence值对ChargeHistory节点进行排序。然后从结果集的第一个(或最后一个,取决于排序顺序)节点获取数据。
Here's a minimized example:
这是一个最小化的例子:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/Integration">
<output>
<xsl:apply-templates select="Case/Charge"/>
</output>
</xsl:template>
<xsl:template match="Charge">
<Charge>
<xsl:for-each select="ChargeHistory[@Stage='Disposition Event']">
<xsl:sort select="@DispositionEventSequence" data-type="number" order="descending"/>
<xsl:if test="position()=1">
<ChargeNumber>
<xsl:value-of select="ChargeNumber"/>
</ChargeNumber>
<StatuteCode>
<xsl:value-of select="Statute/StatuteCode"/>
</StatuteCode>
<!-- get more data as needed -->
</xsl:if>
</xsl:for-each>
</Charge>
</xsl:template>
</xsl:stylesheet>
Edit:
In response to:
回应:
If, Stage=”Disposition Event” is found verify the number of DispositionEventSequence. If only “1” populate Charge Information, otherwise use the highest DispositionEventSequence to populate.
如果找到Stage =“Disposition Event”,则验证DispositionEventSequence的数量。如果只有“1”填充Charge Information,否则使用最高的DispositionEventSequence来填充。
If no Stage=”Disposition Event” is found look for Stage=”Case Filing” to populate. If only “1” populate Charge information, otherwise use the highest Case Filing Filing Sequence to populate.
如果找不到Stage =“Disposition Event”,则查找Stage =“Case Filing”以填充。如果只有“1”填充Charge信息,否则使用最高的Case Filing Filing Sequence来填充。
I believe this translates to: sort the records by Stage (Disposition Event
first), then by their respective Sequence number:
我相信这转化为:按Stage(首先是Disposition Event)排序记录,然后按各自的序号排序:
<xsl:template match="Charge">
<Charge>
<xsl:for-each select="ChargeHistory[@Stage='Disposition Event' or @Stage='Case Filing']">
<xsl:sort select="number(@Stage='Disposition Event')" data-type="number" order="descending"/>
<xsl:sort select="@FilingSequence" data-type="number" order="descending"/>
<xsl:sort select="@DispositionEventSequence" data-type="number" order="descending"/>
<xsl:if test="position()=1">
<ChargeNumber>
<xsl:value-of select="ChargeNumber"/>
</ChargeNumber>
<StatuteCode>
<xsl:value-of select="Statute/StatuteCode"/>
</StatuteCode>
<!-- get more data as needed -->
</xsl:if>
</xsl:for-each>
</Charge>
</xsl:template>