在以下示例中,XML补贴应分组为“Number” - 节点值。我已经尝试过分组Muenchian方法,但还没有完成它。 XSLT必须是1.0。对于每个Number-node,应创建一个框,并将每个值分组。问题也可能是节点中的多个值,这些值应单独显示。感谢您给我的任何帮助!
<ROOT>
<PROC>
<DATA>
<Number>002</Number>
<Registration>27754</Registration>
<Country>Finland</Country>
<DATA>
<PROC>
<PROC>
<DATA>
<Number>003</Number>
<Registration>42852</Registration>
<Country>Sweden</Country>
<DATA>
<PROC>
<PROC>
<DATA>
<Number>003</Number>
<Registration>H/11/019|H/11/020|H/11/021</Registration>
<Country>Slovenia</Country>
<DATA>
<PROC>
<PROC>
<DATA>
<Number>002</Number>
<Registration>19481</Registration>
<Country>Denmark</Country>
<DATA>
<PROC>
<PROC>
<DATA>
<Number>004</Number>
<Registration>09-23</Registration>
<Country>Norway</Country>
<DATA>
<PROC>
</ROOT>
以上代码应如下所示:
<main>
<rbox>
<vNumber>002</vNumber>
<bbox>
<State>Finland</State>
<gbox>
<Registrations>
<Registration>27754</Registration>
</Registrations>
</gbox>
</bbox>
<bbox>
<State>Denmark</State>
<gbox>
<Registrations>
<Registration>19481</Registration>
</Registrations>
</gbox>
</bbox>
</rbox>
<rbox>
<vNumber>003</vNumber>
<bbox>
<State>Slovenia</State>
<gbox>
<Registrations>
<Registration>H/11/019</Registration>
</Registrations>
<Registrations>
<Registration>H/11/020</Registration>
</Registrations>
<Registrations>
<Registration>H/11/021</Registration>
</Registrations>
</gbox>
</bbox>
<bbox>
<State>Sweden</State>
<gbox>
<Registrations>
<Registration>42852</Registration>
</Registrations>
</gbox>
</bbox>
</rbox>
...
</main>
感谢您的快速回复。到目前为止,这是我的代码。我无法在不创建多个值的情况下将Country和Registration Data排序到数字记录。我还尝试在“使用”键中使用连接值,但这也不起作用。
<xsl:key name="country" match="ROOT/PROC/DATA" use="Country"/>
<xsl:key name="registration" match="ROOT/PROC/DATA" use="Registration"/>
<xsl:template match="/">
<main>
<xsl:for-each select="//Number[not(.=preceding::*)]">
<rbox>
<xsl:element name="vNumber">
<vNumber><xsl:value-of select="."/></vNumber>
<xsl:for-each select="//DATA[generate-id() = generate-id(key('country', Country)[1])]">
<bbox>
<State><xsl:value-of select="Country"/></State>
<gbox>
<xsl:for-each select="//DATA[generate-id() = generate-id(key('registration', Registration)[1])]">
<Registrations>
<Registration><xsl:value-of select="Registration"/></Registration>
</Registrations>
</xsl:for-each>
</gbox>
</bbox>
</xsl:for-each>
</xsl:element>
</rbox>
</xsl:for-each>
</main>
</xsl:template>
****编辑:在michael.hor257k关于分组问题的帮助下完成样式表---&gt;有关产品
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"
xmlns:maa="http://www.oma.trp/maa/"
xmlns:rdm="http://www.oma.trp/dictionary/"
xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:param name="ns-prefix" select="'xfa'"/>
<xsl:param name="ns-namespace" select="'http://www.xfa.org/schema/xfa-data/1.0/'"/>
<xsl:param name="ns-prefix1" select="'maa'"/>
<xsl:param name="ns-namespace1" select="'http://www.oma.trp/maa/'"/>
<xsl:param name="ns-prefix2" select="'rdm'"/>
<xsl:param name="ns-namespace2" select="'http://www.oma.trp/dictionary/'"/>
<xsl:param name="ns-prefix3" select="'xsi'"/>
<xsl:param name="ns-namespace3" select="'http://www.w3.org/2001/XMLSchemainstance'"/>
<xsl:param name="ns-prefix4" select="'schemaLocation'"/>
<xsl:param name="ns-namespace4" select="'http://www.oma.trp/maa/variations.xsd'"/>
<xsl:param name="ns-schema" select="'http://www.oma.trp/maa/variations.xsd'"/>
<xsl:variable name="vRdm" select="document('')/*/namespace::*[name()='rdm']"/>
<xsl:variable name="vXsi" select="document('')/*/namespace::*[name()='xsi']"/>
<xsl:variable name="vSchemaLocation" select="document('')/*/namespace::*[name()='schemaLocation']"/>
<xsl:template match="/">
<xsl:element name="{$ns-prefix}:data" namespace="{$ns-namespace}">
<xsl:element name="{$ns-prefix1}:eu_application_form" namespace="{$ns-namespace1}">
<xsl:copy-of select="$vRdm"/>
<xsl:copy-of select="$vXsi"/>
<xsl:copy-of select="$vSchemaLocation"/>
<xsl:attribute name="xsi:schemaLocation">
<xsl:value-of select="$ns-schema" />
</xsl:attribute>
<xsl:template match="/">
<maa:variations-form>
<xsl:element name="{$ns-prefix1}:applicationInformation">
<xsl:element name="{$ns-prefix1}:human">1</xsl:element>
<xsl:element name="{$ns-prefix1}:veterinary">0</xsl:element>
<xsl:element name="{$ns-prefix1}:nationalAuthInMRP">1</xsl:element>
<xsl:element name="{$ns-prefix1}:euAuthorisation">0</xsl:element>
<xsl:element name="{$ns-prefix1}:nationalAuthorisation">0</xsl:element>
<xsl:element name="{$ns-prefix1}:procedureNumbers">
<xsl:element name="{$ns-prefix1}:procedureNumber"></xsl:element>
</xsl:element>
<!--RMS country Loop start -->
<xsl:template match="/">
<xsl:element name="{$ns-prefix1}:referenceMemberState">
<xsl:choose>
<xsl:when test="ROOT/PROC/DATA/Procedure_Number[contains(text(),'DK')]">
<xsl:text>Denmark</xsl:text>
</xsl:when>
<xsl:when test="ROOT/PROC/DATA/Procedure_Number[contains(text(),'SI')]">
<xsl:text>Slovenia</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:element>
</xsl:template>
<!--RMS country Loop end -->
<!--CMS country Loop start -->
<xsl:template match="/">
<xsl:for-each select="//Country_Name[not(.=preceding::*)]">
<maa:concernedMemberStates>
<maa:concernedMemberState><xsl:value-of select="."/></maa:concernedMemberState>
</maa:concernedMemberStates>
</xsl:for-each>
</xsl:template>
<!--CMS country Loop end -->
<!--CONCERNED PRODUCTS -->
</xsl:element>
<xsl:template match="/">
<main>
<products>
<maa:formAndStrengthFlag>0</maa:formAndStrengthFlag>
<maa:footnote/>
<!--CONCERNED PRODUCTS -->
<xsl:key name="strength" match="ROOT/PROC/DATA" use="Speciality_Number"/>
<xsl:for-each select="ROOT/PROC/DATA[generate-id() = generate-id(key('strength', Speciality_Number)[1])]">
<redbox>
<variationNumber><xsl:value-of select="Speciality_Number"/></variationNumber>
<!-- for each member of the current group -->
<xsl:for-each select="key('strength', Speciality_Number)">
<blueBox>
<memberState><xsl:value-of select="Country_Name"/></memberState>
<greenBox>
<maNumbers>
<maNumber><xsl:value-of select="Registration_Number"/></maNumber>
</maNumbers>
</greenBox>
</blueBox>
</xsl:for-each>
</redbox>
</xsl:for-each>
</products>
</main>
</xsl:template>
</maa:variations-form>
</xsl:template>
</xsl:element>
<xsl:element name="FSTEMPLATE_">/Applications/eAFForms/1.20/Forms/Variation/Form/variation.xdp
</xsl:element>
<xsl:element name="FSFORMQUERY_">/Applications/eAFForms/1.20/Forms/Variation/Form/variation.xdp
</xsl:element>
<xsl:element name="FSTRANSFORMATIONID_">PDFForm</xsl:element>
<xsl:element name="FSTARGETURL_"/>
<xsl:element name="FSAWR_"/>
<xsl:element name="FSWR_"/>
<xsl:element name="FSCRURI_">repository://</xsl:element>
<xsl:element name="FSBASEURL_"/>
</xsl:element>
</xsl:template>
答案 0 :(得分:0)
如果您想按DATA
对Number
元素进行分组,则需要将密钥匹配DATA
并使用Number
。
尝试以下样式表:
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:key name="grp" match="DATA" use="Number"/>
<xsl:template match="/ROOT">
<main>
<!-- create a group for each distinct Number -->
<xsl:for-each select="PROC/DATA[generate-id() = generate-id(key('grp', Number)[1])]">
<rbox>
<vNumber>
<xsl:value-of select="Number"/>
</vNumber>
<!-- for each member of the current group -->
<xsl:for-each select="key('grp', Number)">
<bbox>
<State>
<xsl:value-of select="Country"/>
</State>
<gbox>
<Registrations>
<xsl:copy-of select="Registration"/>
</Registrations>
</gbox>
</bbox>
</xsl:for-each>
</rbox>
</xsl:for-each>
</main>
</xsl:template>
</xsl:stylesheet>
您的输入不是格式良好的XML,但是当上面的样式表应用于以下输入时:
<强> XML 强>
<ROOT>
<PROC>
<DATA>
<Number>002</Number>
<Registration>27754</Registration>
<Country>Finland</Country>
</DATA>
</PROC>
<PROC>
<DATA>
<Number>003</Number>
<Registration>42852</Registration>
<Country>Sweden</Country>
</DATA>
</PROC>
<PROC>
<DATA>
<Number>003</Number>
<Registration>H/11/019|H/11/020|H/11/021</Registration>
<Country>Slovenia</Country>
</DATA>
</PROC>
<PROC>
<DATA>
<Number>002</Number>
<Registration>19481</Registration>
<Country>Denmark</Country>
</DATA>
</PROC>
<PROC>
<DATA>
<Number>004</Number>
<Registration>09-23</Registration>
<Country>Norway</Country>
</DATA>
</PROC>
</ROOT>
结果将是:
<?xml version="1.0" encoding="UTF-8"?>
<main>
<rbox>
<vNumber>002</vNumber>
<bbox>
<State>Finland</State>
<gbox>
<Registrations>
<Registration>27754</Registration>
</Registrations>
</gbox>
</bbox>
<bbox>
<State>Denmark</State>
<gbox>
<Registrations>
<Registration>19481</Registration>
</Registrations>
</gbox>
</bbox>
</rbox>
<rbox>
<vNumber>003</vNumber>
<bbox>
<State>Sweden</State>
<gbox>
<Registrations>
<Registration>42852</Registration>
</Registrations>
</gbox>
</bbox>
<bbox>
<State>Slovenia</State>
<gbox>
<Registrations>
<Registration>H/11/019|H/11/020|H/11/021</Registration>
</Registrations>
</gbox>
</bbox>
</rbox>
<rbox>
<vNumber>004</vNumber>
<bbox>
<State>Norway</State>
<gbox>
<Registrations>
<Registration>09-23</Registration>
</Registrations>
</gbox>
</bbox>
</rbox>
</main>