1
我想使用Muenchian分組(第一次爲我),但有一些ploblems。 我想我犯了一些邏輯錯誤,但我不明白如何找到它。如果刪除第一個塊中輸入文件轉換工作正常,但現在不工作:(XSL Muenchian分組
Source
<?xml version="1.0" encoding="utf-8"?>
<ROOT xsi:schemaLocation="http://www.av.com/pu" Name="StaffManagers" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.av.pu/pu">
<Data>
<Part>
<ReportPart1>
<Details>
<Detail BlokName="Accountant">
<Number>1.1.9</Number>
<Content>Y</Content>
<Id>CInfo</Id>
<Collection_Id>11.001.001.009.001</Collection_Id>
</Detail>
<Detail BlokName="Accountant" Id="CollEduEx">
<Number>1.1.9.1</Number>
<Content>College</Content>
<Suffix>NameEx</Suffix>
<Id>CollEduEx</Id>
<Collection_Id>11.001.001.009.001</Collection_Id>
</Detail>
<Detail BlokName="Accountant" Id="CollEduEx">
<Number>1.1.9.2</Number>
<Content>1 981</Content>
<Suffix>YEx</Suffix>
<Id>CollEduEx</Id>
<Collection_Id>11.001.001.009.001</Collection_Id>
</Detail>
<Detail BlokName="Accountant" Id="CollEduEx">
<Number>1.1.9.3</Number>
<Content>XX4793</Content>
<Suffix>DEx</Suffix>
<Id>CollEduEx</Id>
<Collection_Id>11.001.001.009.001</Collection_Id>
</Detail>
<Detail BlokName="Accountant" Id="CollEduEx">
<Number>1.1.9.4</Number>
<Content>Networks</Content>
<Suffix>SEx</Suffix>
<Id>CollEduEx</Id>
<Collection_Id>11.001.001.009.001</Collection_Id>
</Detail>
<Detail BlokName="Accountant" Id="CollEduEx">
<Number>1.1.9.5</Number>
<Content>Eng</Content>
<Suffix>QEx</Suffix>
<Id>CollEduEx</Id>
<Collection_Id>11.001.001.009.001</Collection_Id>
</Detail>
<Detail BlokName="Accountant" Id="CollEduEx">
<Number>1.1.9.1</Number>
<Content>Uni</Content>
<Suffix>NameEx</Suffix>
<Id>CollEduEx</Id>
<Collection_Id>11.001.001.009.002</Collection_Id>
</Detail>
<Detail BlokName="Accountant" Id="CollEduEx">
<Number>1.1.9.2</Number>
<Content>1 999</Content>
<Suffix>YEx</Suffix>
<Id>CollEduEx</Id>
<Collection_Id>11.001.001.009.002</Collection_Id>
</Detail>
<Detail BlokName="Accountant" Id="CollEduEx">
<Number>1.1.9.3</Number>
<Content>DFC12</Content>
<Suffix>DEx</Suffix>
<Id>CollEduEx</Id>
<Collection_Id>11.001.001.009.002</Collection_Id>
</Detail>
<Detail BlokName="Accountant" Id="CollEduEx">
<Number>1.1.9.4</Number>
<Content>Acciy</Content>
<Suffix>SEx</Suffix>
<Id>CollEduEx</Id>
<Collection_Id>11.001.001.009.002</Collection_Id>
</Detail>
<Detail BlokName="Accountant" Id="CollEduEx">
<Number>1.1.9.5</Number>
<Content>Eco</Content>
<Suffix>QEx</Suffix>
<Id>CollEduEx</Id>
<Collection_Id>11.001.001.009.002</Collection_Id>
</Detail>
</Details>
</ReportPart1>
</Part>
</Data>
</ROOT>
</i>
XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:mn="http://www.w3.org/2005/xpath-functions/add"
version="1.0"
xmlns:av="http://www.av.pu/pu"
xmlns:scr="urn:scr.this"
>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template name="create_element">
<xsl:param name="element_name"/>
<xsl:element name="av:{$element_name}">
<xsl:value-of select="av:Content" />
</xsl:element>
</xsl:template>
<xsl:template name="create_block">
<xsl:param name="block_name"/>
<xsl:for-each select="av:Data/av:Part/av:ReportPart1/av:Details/av:Detail[@BlokName=$block_name]">
<xsl:if test ="av:Content != ''">
<xsl:choose>
<xsl:when test="av:Suffix"/>
<xsl:otherwise>
<xsl:variable name="elementname">
<xsl:value-of select="av:Id"/>
</xsl:variable>
<xsl:call-template name="create_element">
<xsl:with-param name="element_name" select="$elementname"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
<xsl:call-template name="create_collections">
<xsl:with-param name="block_name" select="$block_name"/>
<xsl:with-param name="collection_name">CollEduEx</xsl:with-param>
<xsl:with-param name="collection_element_name">EducationExecutive</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:key name="Collection_Id" match="*" use="av:Collection_Id" />
<xsl:template name="create_collections">
<xsl:param name="block_name"/>
<xsl:param name="collection_name"/>
<xsl:param name="collection_element_name"/>
<xsl:element name="{$collection_name}">
<xsl:for-each select="av:Data/av:Part/av:ReportPart1/av:Details/av:Detail[@BlokName=$block_name and av:Id=$collection_name and generate-id(.)=generate-id(key('Collection_Id',av:Collection_Id))]">
<xsl:element name="{$collection_element_name}">
<xsl:for-each select="key('Collection_Id',av:Collection_Id)">
<xsl:variable name="elementname">
<xsl:value-of select="av:Suffix"/>
</xsl:variable>
<xsl:call-template name="create_element">
<xsl:with-param name="element_name" select="$elementname"/>
</xsl:call-template>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
<xsl:template name="show_name">
<xsl:param name="element" />
<xsl:value-of select="normalize-space($element)"/>
</xsl:template>
<xsl:template match="av:ROOT">
<xsl:element name="av:Part1">
<xsl:call-template name="create_block">
<xsl:with-param name="block_name">CIO</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="create_block">
<xsl:with-param name="block_name">Accountant</xsl:with-param>
</xsl:call-template>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
預期結果
<av:Part1 xmlns:av="http://www.av.pu/pu">
<CollEduEx/>
<av:CInfo>Y</av:CInfo>
<CollEduEx>
<EducationExecutive>
<av:NameEx>College</av:NameEx>
<av:YEx>1 981</av:YEx>
<av:DEx>XX4793</av:DEx>
<av:SEx>Networks</av:SEx>
<av:QEx>Eng</av:QEx>
</EducationExecutive>
<EducationExecutive>
<av:NameEx>Uni</av:NameEx>
<av:YEx>1 999</av:YEx>
<av:DEx>DFC12</av:DEx>
<av:SEx>Acciy</av:SEx>
<av:QEx>Eco</av:QEx>
</EducationExecutive>
</CollEduEx>
</av:Part1>
「*如果我刪除輸入文件轉換工作的第一個塊,但現在不工作*」確切的問題是什麼?什麼是「*工作正常*」和「*現在不工作*」? – potame