XSLT v1.0 Grouping

13 views
Skip to first unread message

rob_...@hotmail.com

unread,
Nov 26, 2014, 2:50:48 AM11/26/14
to xs...@googlegroups.com

G'day,

Having issue getting my XSLT v1.0 grouping working. I beleive I'm not creating the key correctly, but as you can guess I've tried most things and hope an expert out there can point me in the wrtiew direction.

I want to group DataPointMaps on the time element embedded inside of the DataPointMap

Please see XML and my muliple attempts below. I will continue trying, but I have a deadline to make and will appreciate any help.

<ns0:DataPointMappings xmlns:ns0="http://QUASAR/Common/IntegrationData">
 <ns0:DataPointMap>
  <ns0:SourceDataPoint>
   <ns0:DataPoint>MWT.PHD2ROT.HOURLY.REF.01</ns0:DataPoint>
   <ns0:DataPointDetail>
    <ns0:Item>MWT.PHD2ROT.HOURLY.REF.01</ns0:Item>
    <ns0:Value>Arse</ns0:Value>
    <ns0:Confidence>100</ns0:Confidence>
    <ns0:Time>2014-11-25T13:00:00</ns0:Time>
   </ns0:DataPointDetail>
  </ns0:SourceDataPoint>
  <ns0:DestinationDataPoint>
   <ns0:DataPoint>MWT.PHD2ROT.HOURLY.REF.01.DEST</ns0:DataPoint>
  </ns0:DestinationDataPoint>
 </ns0:DataPointMap>
 <ns0:DataPointMap>
  <ns0:SourceDataPoint>
   <ns0:DataPoint>MWT.PHD2ROT.HOURLY.REF.02</ns0:DataPoint>
   <ns0:DataPointGUID>327f2b2b-f605-485e-8f3c-7e855c2dc5cb</ns0:DataPointGUID>
   <ns0:DataPointDetail>
    <ns0:Item>MWT.PHD2ROT.HOURLY.REF.02</ns0:Item>
    <ns0:Value>Arse</ns0:Value>
    <ns0:Confidence>100</ns0:Confidence>
    <ns0:Time>2014-11-25T13:00:00</ns0:Time>
   </ns0:DataPointDetail>
  </ns0:SourceDataPoint>
  <ns0:DestinationDataPoint>
   <ns0:DataPoint>MWT.PHD2ROT.HOURLY.REF.02.DEST</ns0:DataPoint>
  </ns0:DestinationDataPoint>
 </ns0:DataPointMap>
 <ns0:DataPointMap>
  <ns0:SourceDataPoint>
   <ns0:DataPoint>MWT.PHD2ROT.HOURLY.REF.03</ns0:DataPoint>
   <ns0:DataPointDetail>
    <ns0:Item>MWT.PHD2ROT.HOURLY.REF.03</ns0:Item>
    <ns0:Value>Arse</ns0:Value>
    <ns0:Confidence>100</ns0:Confidence>
    <ns0:Time>2014-11-25T10:00:00</ns0:Time>
   </ns0:DataPointDetail>
  </ns0:SourceDataPoint>
  <ns0:DestinationDataPoint>
   <ns0:DataPoint>MWT.PHD2ROT.HOURLY.REF.03.DEST</ns0:DataPoint>
  </ns0:DestinationDataPoint>
 </ns0:DataPointMap>
 <ns0:DataPointMap>
  <ns0:SourceDataPoint>
   <ns0:DataPoint>MWT.PHD2ROT.HOURLY.REF.01</ns0:DataPoint>
   <ns0:DataPointDetail>
    <ns0:Item>MWT.PHD2ROT.HOURLY.REF.01</ns0:Item>
    <ns0:Value>Arse</ns0:Value>
    <ns0:Confidence>100</ns0:Confidence>
    <ns0:Time>2014-11-25T10:00:00</ns0:Time>
   </ns0:DataPointDetail>
  </ns0:SourceDataPoint>
  <ns0:DestinationDataPoint>
   <ns0:DataPoint>MWT.PHD2ROT.HOURLY.REF.01.DEST</ns0:DataPoint>
  </ns0:DestinationDataPoint>
 </ns0:DataPointMap>
</ns0:DataPointMappings>


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
 <!ENTITY nl "&#xd;&#xa;">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://QUASAR/Common/IntegrationData">

 <xsl:key name="phdTimeGrouping" match="ns0:DataPointMapping/ns0:DataPointMap" use="/ns0:SourceDataPoint/ns0:DataPointDetail/ns0:Time"/>

 <xsl:output method="text" indent="yes" />
 
 <xsl:template match="/">
  <xsl:text>Hello XLST</xsl:text>
  <xsl:text>&nl;</xsl:text>
  <xsl:apply-templates select="/ns0:DataPointMappings" />
 </xsl:template >

 
 <!-- Method 1 -->
 
 <xsl:template match="ns0:DataPointMappings">
  <xsl:for-each select="ns0:DataPointMap[count(. | key('phdTimeGrouping',/ns0:SourceDataPoint/ns0:DataPointDetail/ns0:Time)[1]) = 1]">

   <xsl:text>Group loop &#032;</xsl:text>
   <xsl:value-of select="/ns0:SourceDataPoint/ns0:DataPoint"/>
   
   <xsl:for-each select="key('phdTimeGrouping', /ns0:SourceDataPoint/ns0:DataPointDetail/ns0:Time)">
    <xsl:text>Data Map Loop &#032;</xsl:text>
   </xsl:for-each>
   <xsl:text>&nl;</xsl:text>
  </xsl:for-each>
 </xsl:template>

 <!-- Method Two -->
 
 <!--<xsl:template match="ns0:DataPointMappings">
  <xsl:for-each select="/ns0:DataPointMap[generate-id() = generate-id(key('phdTimeGrouping',text())[1])]">

   <xsl:value-of select="/ns0:SourceDataPoint/ns0:DataPoint"/>
   <xsl:text>Group loop&#032;</xsl:text>

   <xsl:for-each select="key('phdTimeGrouping', /ns0:SourceDataPoint/ns0:DataPointDetail/ns0:Time)">

    <xsl:text>Data Map Loop &#032;</xsl:text>
   </xsl:for-each>
   <xsl:text>&nl;</xsl:text>
  </xsl:for-each>
 </xsl:template>-->
 
</xsl:stylesheet>

Reply all
Reply to author
Forward
0 new messages