如何使用 Group By 子句
How to use the Group By Clause
我正在尝试为 XML 数据实现 XSLT 映射。
这是我要找的东西。
输入XML:
<ListOfPersons xmlns="http://ws.wso2.org/dataservice">
<PersonDisclosureDate>
<Emplid>123456</Emplid>
<uniqname>abcd</uniqname>
<HasDisclosed>0</HasDisclosed>
<HasDisclosedThisFY>1</HasDisclosedThisFY>
<LastDiscloseDt></LastDiscloseDt>
<HasInterest>1</HasInterest>
<oeID>FI00006088</oeID>
<oeName>ArborSense, Inc.</oeName>
<oeStatus>Under Modification</oeStatus>
<oeSignDate>2016-07-15T15:53:42.000-04:00</oeSignDate>
<relationship>ID00000001</relationship>
<Types>Equity Interest - Non-Public::Advisory, Strategic, Scientific, or Medical Board; and/or Government Agency::Leadership Role</Types>
<startdt>2016-02-08T00:00:00.000-05:00</startdt>
<enddt/>
<oeDCstate>Department Review</oeDCstate>
</PersonDisclosureDate>
<PersonDisclosureDate>
<Emplid>23456</Emplid>
<uniqname>pqr</uniqname>
<HasDisclosed>0</HasDisclosed>
<HasDisclosedThisFY>1</HasDisclosedThisFY>
<LastDiscloseDt></LastDiscloseDt>
<HasInterest>1</HasInterest>
<oeID>FI00003483</oeID>
<oeName>Dimension Therapeutics</oeName>
<oeStatus>Under Modification</oeStatus>
<oeSignDate>2016-09-30T09:09:05.000-04:00</oeSignDate>
<relationship>ID00000001</relationship>
<Types>Consultant</Types>
<startdt>2014-11-18T00:00:00.000-05:00</startdt>
<enddt/>
<oeDCstate>Department Review</oeDCstate>
</PersonDisclosureDate>
<PersonDisclosureDate>
<Emplid>23456</Emplid>
<uniqname>pqr</uniqname>
<HasDisclosed>0</HasDisclosed>
<HasDisclosedThisFY>1</HasDisclosedThisFY>
<LastDiscloseDt></LastDiscloseDt>
<HasInterest>1</HasInterest>
<oeID>FI00007824</oeID>
<oeName>intercept</oeName>
<oeStatus>Under Modification</oeStatus>
<oeSignDate>2016-09-30T09:09:58.000-04:00</oeSignDate>
<relationship>ID00000001</relationship>
<Types>Advisory, Strategic, Scientific, or Medical Board; and/or Government Agency::Travel</Types>
<startdt>2016-10-05T00:00:00.000-04:00</startdt>
<enddt/>
<oeDCstate>Department Review</oeDCstate>
</PersonDisclosureDate>
<PersonDisclosureDate>
<Emplid>23456</Emplid>
<uniqname>pqr</uniqname>
<HasDisclosed>0</HasDisclosed>
<HasDisclosedThisFY>1</HasDisclosedThisFY>
<LastDiscloseDt></LastDiscloseDt>
<HasInterest>1</HasInterest>
<oeID>FI00007823</oeID>
<oeName>wilson therapeutics</oeName>
<oeStatus>Under Modification</oeStatus>
<oeSignDate>2016-09-30T09:09:31.000-04:00</oeSignDate>
<relationship>ID00000001</relationship>
<Types>Advisory, Strategic, Scientific, or Medical Board; and/or Government Agency::Travel</Types>
<startdt>2016-11-09T00:00:00.000-05:00</startdt>
<enddt/>
<oeDCstate>Department Review</oeDCstate>
</PersonDisclosureDate>
<PersonDisclosureDate>
<Emplid>34567</Emplid>
<uniqname>xyz</uniqname>
<HasDisclosed xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<HasDisclosedThisFY>0</HasDisclosedThisFY>
<LastDiscloseDt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<HasInterest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<oeID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<oeName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<oeStatus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<oeSignDate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<relationship xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<Types xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<startdt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<enddt/>
<oeDCstate/>
</PersonDisclosureDate>
</ListOfPersons>
预期响应:
<?xml version="1.0" encoding="UTF-8"?>
<DisclosureData xsi:noNamespaceSchemaLocation="C:/XSL/eResearch_Expected_Response.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<count>3</count>
<disclosures>
<uniqName>abcd</uniqName>
<hasDisclosed>0</hasDisclosed>
<lastDiscloseDt></lastDiscloseDt>
<disclosureRecords>
<oeId>FI00006088</oeId>
<oeName>ArborSense, Inc.</oeName>
<oeSignDate>2016-07-15T15:53:42.000-04:00</oeSignDate>
<oeRelationship>ID00000001</oeRelationship>
<oeTypes>Equity Interest - Non-Public::Advisory, Strategic, Scientific, or Medical Board; and/or Government Agency::Leadership Role</oeTypes>
<oeStartDt>2016-02-08T00:00:00.000-05:00</oeStartDt>
<oeEndDt/>
</disclosureRecords>
</disclosures>
<disclosures>
<uniqName>pqr</uniqName>
<hasDisclosed>0</hasDisclosed>
<lastDiscloseDt></lastDiscloseDt>
<disclosureRecords>
<oeId>FI00003483</oeId>
<oeName>Dimension Therapeutics</oeName>
<oeSignDate>2016-09-30T09:09:05.000-04:00</oeSignDate>
<oeRelationship>ID00000001</oeRelationship>
<oeTypes>Consultant</oeTypes>
<oeStartDt>2014-11-18T00:00:00.000-05:00</oeStartDt>
<oeEndDt/>
</disclosureRecords>
<disclosureRecords>
<oeId>FI00007824</oeId>
<oeName>intercept</oeName>
<oeSignDate>2016-09-30T09:09:58.000-04:00</oeSignDate>
<oeRelationship>ID00000001</oeRelationship>
<oeTypes>Advisory, Strategic, Scientific, or Medical Board; and/or Government Agency::Travel</oeTypes>
<oeStartDt>2016-10-05T00:00:00.000-04:00</oeStartDt>
<oeEndDt/>
</disclosureRecords>
<disclosureRecords>
<oeId>FI00007823</oeId>
<oeName>wilson therapeutics</oeName>
<oeSignDate>2016-09-30T09:09:31.000-04:00</oeSignDate>
<oeRelationship>ID00000001</oeRelationship>
<oeTypes>Advisory, Strategic, Scientific, or Medical Board; and/or Government Agency::Travel</oeTypes>
<oeStartDt>2016-11-09T00:00:00.000-05:00</oeStartDt>
<oeEndDt/>
</disclosureRecords>
</disclosures>
<disclosures>
<uniqName>xyz</uniqName>
<hasDisclosed/>
<lastDiscloseDt/>
<disclosureRecords>
<oeId/>
<oeName/>
<oeSignDate/>
<oeRelationship/>
<oeTypes/>
<oeStartDt/>
<oeEndDt/>
</disclosureRecords>
</disclosures>
</DisclosureData>
我尝试使用 ALtova Mapforce 工具来映射 xml 但没有得到正确的结果。
Altova 映射:
有人可以提供一些指导,说明如何使用 Altova Mapforce 或什至使用 group by 标签的普通 XSLT 文档来实现上述结果吗?
提前致谢,
克兰西
这似乎是一个简单的 for-each-group 选择 PersonDisclosureDate
并按 uniqname
分组。
为了简单起见,这里有一个使用拉取方法的基本示例...
XSLT 2.0(此处的工作示例:http://xsltfiddle.liberty-development.net/nbUY4kp)
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="http://ws.wso2.org/dataservice">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<DisclosureData xsi:noNamespaceSchemaLocation="C:/XSL/eResearch_Expected_Response.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<count><xsl:value-of select="count(distinct-values(/*/PersonDisclosureDate/uniqname))"/></count>
<xsl:for-each-group select="PersonDisclosureDate" group-by="uniqname">
<disclosures>
<uniqName><xsl:value-of select="current-grouping-key()"/></uniqName>
<hasDisclosed><xsl:value-of select="current-group()[1]/HasDisclosed"/></hasDisclosed>
<lastDiscloseDt><xsl:value-of select="current-group()[1]/LastDiscloseDt"/></lastDiscloseDt>
<xsl:for-each select="current-group()">
<disclosureRecords>
<oeId><xsl:value-of select="oeID"/></oeId>
<oeName><xsl:value-of select="oeName"/></oeName>
<oeSignDate><xsl:value-of select="oeSignDate"/></oeSignDate>
<oeRelationship><xsl:value-of select="relationship"/></oeRelationship>
<oeTypes><xsl:value-of select="Types"/></oeTypes>
<oeStartDt><xsl:value-of select="startdt"/></oeStartDt>
<oeEndDt><xsl:value-of select="enddt"/></oeEndDt>
</disclosureRecords>
</xsl:for-each>
</disclosures>
</xsl:for-each-group>
</DisclosureData>
</xsl:template>
</xsl:stylesheet>
我正在尝试为 XML 数据实现 XSLT 映射。
这是我要找的东西。
输入XML:
<ListOfPersons xmlns="http://ws.wso2.org/dataservice">
<PersonDisclosureDate>
<Emplid>123456</Emplid>
<uniqname>abcd</uniqname>
<HasDisclosed>0</HasDisclosed>
<HasDisclosedThisFY>1</HasDisclosedThisFY>
<LastDiscloseDt></LastDiscloseDt>
<HasInterest>1</HasInterest>
<oeID>FI00006088</oeID>
<oeName>ArborSense, Inc.</oeName>
<oeStatus>Under Modification</oeStatus>
<oeSignDate>2016-07-15T15:53:42.000-04:00</oeSignDate>
<relationship>ID00000001</relationship>
<Types>Equity Interest - Non-Public::Advisory, Strategic, Scientific, or Medical Board; and/or Government Agency::Leadership Role</Types>
<startdt>2016-02-08T00:00:00.000-05:00</startdt>
<enddt/>
<oeDCstate>Department Review</oeDCstate>
</PersonDisclosureDate>
<PersonDisclosureDate>
<Emplid>23456</Emplid>
<uniqname>pqr</uniqname>
<HasDisclosed>0</HasDisclosed>
<HasDisclosedThisFY>1</HasDisclosedThisFY>
<LastDiscloseDt></LastDiscloseDt>
<HasInterest>1</HasInterest>
<oeID>FI00003483</oeID>
<oeName>Dimension Therapeutics</oeName>
<oeStatus>Under Modification</oeStatus>
<oeSignDate>2016-09-30T09:09:05.000-04:00</oeSignDate>
<relationship>ID00000001</relationship>
<Types>Consultant</Types>
<startdt>2014-11-18T00:00:00.000-05:00</startdt>
<enddt/>
<oeDCstate>Department Review</oeDCstate>
</PersonDisclosureDate>
<PersonDisclosureDate>
<Emplid>23456</Emplid>
<uniqname>pqr</uniqname>
<HasDisclosed>0</HasDisclosed>
<HasDisclosedThisFY>1</HasDisclosedThisFY>
<LastDiscloseDt></LastDiscloseDt>
<HasInterest>1</HasInterest>
<oeID>FI00007824</oeID>
<oeName>intercept</oeName>
<oeStatus>Under Modification</oeStatus>
<oeSignDate>2016-09-30T09:09:58.000-04:00</oeSignDate>
<relationship>ID00000001</relationship>
<Types>Advisory, Strategic, Scientific, or Medical Board; and/or Government Agency::Travel</Types>
<startdt>2016-10-05T00:00:00.000-04:00</startdt>
<enddt/>
<oeDCstate>Department Review</oeDCstate>
</PersonDisclosureDate>
<PersonDisclosureDate>
<Emplid>23456</Emplid>
<uniqname>pqr</uniqname>
<HasDisclosed>0</HasDisclosed>
<HasDisclosedThisFY>1</HasDisclosedThisFY>
<LastDiscloseDt></LastDiscloseDt>
<HasInterest>1</HasInterest>
<oeID>FI00007823</oeID>
<oeName>wilson therapeutics</oeName>
<oeStatus>Under Modification</oeStatus>
<oeSignDate>2016-09-30T09:09:31.000-04:00</oeSignDate>
<relationship>ID00000001</relationship>
<Types>Advisory, Strategic, Scientific, or Medical Board; and/or Government Agency::Travel</Types>
<startdt>2016-11-09T00:00:00.000-05:00</startdt>
<enddt/>
<oeDCstate>Department Review</oeDCstate>
</PersonDisclosureDate>
<PersonDisclosureDate>
<Emplid>34567</Emplid>
<uniqname>xyz</uniqname>
<HasDisclosed xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<HasDisclosedThisFY>0</HasDisclosedThisFY>
<LastDiscloseDt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<HasInterest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<oeID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<oeName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<oeStatus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<oeSignDate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<relationship xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<Types xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<startdt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<enddt/>
<oeDCstate/>
</PersonDisclosureDate>
</ListOfPersons>
预期响应:
<?xml version="1.0" encoding="UTF-8"?>
<DisclosureData xsi:noNamespaceSchemaLocation="C:/XSL/eResearch_Expected_Response.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<count>3</count>
<disclosures>
<uniqName>abcd</uniqName>
<hasDisclosed>0</hasDisclosed>
<lastDiscloseDt></lastDiscloseDt>
<disclosureRecords>
<oeId>FI00006088</oeId>
<oeName>ArborSense, Inc.</oeName>
<oeSignDate>2016-07-15T15:53:42.000-04:00</oeSignDate>
<oeRelationship>ID00000001</oeRelationship>
<oeTypes>Equity Interest - Non-Public::Advisory, Strategic, Scientific, or Medical Board; and/or Government Agency::Leadership Role</oeTypes>
<oeStartDt>2016-02-08T00:00:00.000-05:00</oeStartDt>
<oeEndDt/>
</disclosureRecords>
</disclosures>
<disclosures>
<uniqName>pqr</uniqName>
<hasDisclosed>0</hasDisclosed>
<lastDiscloseDt></lastDiscloseDt>
<disclosureRecords>
<oeId>FI00003483</oeId>
<oeName>Dimension Therapeutics</oeName>
<oeSignDate>2016-09-30T09:09:05.000-04:00</oeSignDate>
<oeRelationship>ID00000001</oeRelationship>
<oeTypes>Consultant</oeTypes>
<oeStartDt>2014-11-18T00:00:00.000-05:00</oeStartDt>
<oeEndDt/>
</disclosureRecords>
<disclosureRecords>
<oeId>FI00007824</oeId>
<oeName>intercept</oeName>
<oeSignDate>2016-09-30T09:09:58.000-04:00</oeSignDate>
<oeRelationship>ID00000001</oeRelationship>
<oeTypes>Advisory, Strategic, Scientific, or Medical Board; and/or Government Agency::Travel</oeTypes>
<oeStartDt>2016-10-05T00:00:00.000-04:00</oeStartDt>
<oeEndDt/>
</disclosureRecords>
<disclosureRecords>
<oeId>FI00007823</oeId>
<oeName>wilson therapeutics</oeName>
<oeSignDate>2016-09-30T09:09:31.000-04:00</oeSignDate>
<oeRelationship>ID00000001</oeRelationship>
<oeTypes>Advisory, Strategic, Scientific, or Medical Board; and/or Government Agency::Travel</oeTypes>
<oeStartDt>2016-11-09T00:00:00.000-05:00</oeStartDt>
<oeEndDt/>
</disclosureRecords>
</disclosures>
<disclosures>
<uniqName>xyz</uniqName>
<hasDisclosed/>
<lastDiscloseDt/>
<disclosureRecords>
<oeId/>
<oeName/>
<oeSignDate/>
<oeRelationship/>
<oeTypes/>
<oeStartDt/>
<oeEndDt/>
</disclosureRecords>
</disclosures>
</DisclosureData>
我尝试使用 ALtova Mapforce 工具来映射 xml 但没有得到正确的结果。
Altova 映射:
有人可以提供一些指导,说明如何使用 Altova Mapforce 或什至使用 group by 标签的普通 XSLT 文档来实现上述结果吗?
提前致谢, 克兰西
这似乎是一个简单的 for-each-group 选择 PersonDisclosureDate
并按 uniqname
分组。
为了简单起见,这里有一个使用拉取方法的基本示例...
XSLT 2.0(此处的工作示例:http://xsltfiddle.liberty-development.net/nbUY4kp)
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="http://ws.wso2.org/dataservice">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<DisclosureData xsi:noNamespaceSchemaLocation="C:/XSL/eResearch_Expected_Response.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<count><xsl:value-of select="count(distinct-values(/*/PersonDisclosureDate/uniqname))"/></count>
<xsl:for-each-group select="PersonDisclosureDate" group-by="uniqname">
<disclosures>
<uniqName><xsl:value-of select="current-grouping-key()"/></uniqName>
<hasDisclosed><xsl:value-of select="current-group()[1]/HasDisclosed"/></hasDisclosed>
<lastDiscloseDt><xsl:value-of select="current-group()[1]/LastDiscloseDt"/></lastDiscloseDt>
<xsl:for-each select="current-group()">
<disclosureRecords>
<oeId><xsl:value-of select="oeID"/></oeId>
<oeName><xsl:value-of select="oeName"/></oeName>
<oeSignDate><xsl:value-of select="oeSignDate"/></oeSignDate>
<oeRelationship><xsl:value-of select="relationship"/></oeRelationship>
<oeTypes><xsl:value-of select="Types"/></oeTypes>
<oeStartDt><xsl:value-of select="startdt"/></oeStartDt>
<oeEndDt><xsl:value-of select="enddt"/></oeEndDt>
</disclosureRecords>
</xsl:for-each>
</disclosures>
</xsl:for-each-group>
</DisclosureData>
</xsl:template>
</xsl:stylesheet>