0

我在执行此处此处所述的双重变换时遇到问题

我不确定我做错了什么。我为每个第一遍模板指定一个模式,为单个第二遍模板指定一个不同的模式。

我确实遇到了一个问题,即没有使用参数为我的一个模板定义匹配项,因此使用了 match="/"。我还用 XSL 替换了模板调用并得到了相同的结果。

XSLT 代码段:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:ext="http://exslt.org/common" xmlns:ns0="http://www.archer-tech.com/" exclude-result-prefixes="ns0" version="2.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
   <xsl:variable name="vPass1" >
   <xsl:apply-templates select="/*" />
   </xsl:variable> 
   <xsl:apply-templates mode="pass2" select="$vPass1/*"/>
</xsl:template> 

<!--First Pass XSL-->
//see full XSL below

<!-- XSL that transforms the Generic Report Transform Output to the  output we need -->
  <xsl:template match="/ns0:ArcherRecords" mode="pass2">
...etc...

//样本数据//

输入 XML:

<?xml version="1.0" encoding="utf-16"?>
<Records count="1">
  <Metadata>
    <FieldDefinitions>
      <FieldDefinition id="13390" guid="e81f29db-b394-4291-b7ba-4186cf3552fe" name="Tracking ID" alias="Tracking_ID" />
      <FieldDefinition id="13393" guid="50b870c8-3a98-49a9-b96f-32403b1fc4b5" name="Some Type" alias="CMEP_Type" />
      <FieldDefinition id="13394" guid="66f63799-1a00-49ab-8190-e0d1a88640c9" name="Title" alias="Title" />
      <FieldDefinition id="13408" guid="db266517-ac2c-45a4-9479-17712b885a34" name="Svcs Contact" alias="Svcs_Contact" />
      <FieldDefinition id="13947" guid="683d5199-43d1-43c0-b8e6-38c2dcb84125" name="Description" alias="Description" />
      <FieldDefinition id="14054" guid="8dd17c8d-35a8-46b1-8344-3cceb1a8e386" name="Next Processing - Internal Due Date" alias="Next_Processing__Internal_Due_Date" />
      <FieldDefinition id="14434" guid="eef81f9c-bddd-4788-af73-a2019312edf5" name="Next Processing - External Due Date" alias="Next_Processing__External_Due_Date" />
      <FieldDefinition id="13420" guid="0755d891-7926-4489-a7e8-bdc64eda8738" name="Requirement(s)" alias="Requirements" />
      <FieldDefinition id="13423" guid="7f8e6bff-2d88-4937-bf38-94d915c576be" name="Business Unit" alias="Business_Unit" />
      <FieldDefinition id="13424" guid="3abf168b-62dd-4e7c-9ed6-6f8bc4ff4cff" name="Region Entity" alias="Region_Entity" />
      <FieldDefinition id="13425" guid="5cf01097-8176-417a-9380-2df6aa4cf5d1" name="Function" alias="Function" />
      <FieldDefinition id="13473" guid="c108a853-6ff6-4889-a24a-3a9564cc575b" name="BU Coordinator" alias="BU_Coordinator" />
      <FieldDefinition id="13474" guid="75556190-a482-411e-af1f-7259fd4c3d7f" name="Requirement Owner" alias="Requirement_Owner" />
      <FieldDefinition id="13475" guid="4dabb23d-c818-470e-aeac-db854fb0844c" name="SMEs" alias="SMEs" />
    </FieldDefinitions>
  </Metadata>
  <LevelCounts>
    <LevelCount id="180" guid="67d48b12-05b1-4aca-abad-8db9eda174ec" count="3" />
    <LevelCount id="181" guid="eb9b5a20-27af-4dc8-bb6b-1a9806d5fa58" count="17" />
  </LevelCounts>
  <Record contentId="565593" levelId="180" levelGuid="67d48b12-05b1-4aca-abad-8db9eda174ec" moduleId="387" parentId="0">
    <Record contentId="316580" levelId="181" levelGuid="eb9b5a20-27af-4dc8-bb6b-1a9806d5fa58" moduleId="388" parentId="0">
      <Field id="13420" guid="0755d891-7926-4489-a7e8-bdc64eda8738" type="9">
        <Reference id="204182">lAL-007-0 1.</Reference>
      </Field>
      <Field id="13424" guid="3abf168b-62dd-4e7c-9ed6-6f8bc4ff4cff" type="4">
        <ListValues>
          <ListValue id="63031" displayName="RFC">RFC</ListValue>
        </ListValues>
      </Field>
      <Field id="13425" guid="5cf01097-8176-417a-9380-2df6aa4cf5d1" type="4">
        <ListValues>
          <ListValue id="63045" displayName="GaP">GaP</ListValue>
        </ListValues>
      </Field>
      <Field id="13423" guid="7f8e6bff-2d88-4937-bf38-94d915c576be" type="4">
        <ListValues>
          <ListValue id="63053" displayName="CorpOps">CorpOps</ListValue>
        </ListValues>
      </Field>
      <Field id="13473" guid="c108a853-6ff6-4889-a24a-3a9564cc575b" type="8">
        <Users>
          <User id="3480" firstName="Joe" lastName="Smith" domain="CORP">t564847</User>
        </Users>
      </Field>
      <Field id="13474" guid="75556190-a482-411e-af1f-7259fd4c3d7f" type="8">
        <Users>
          <User id="16471" firstName="Doug" lastName="Snyder" domain="main">t54654</User>
        </Users>
      </Field>
      <Field id="13475" guid="4dabb23d-c818-470e-aeac-db854fb0844c" type="8">
        <Users>
          <User id="3480" firstName="Peter" lastName="Murphy" domain="CORP">z564156</User>
        </Users>
      </Field>
    </Record>
    <Record contentId="316581" levelId="181" levelGuid="eb9b5a20-27af-4dc8-bb6b-1a9806d5fa58" moduleId="388" parentId="0">
      <Field id="13420" guid="0755d891-7926-4489-a7e8-bdc64eda8738" type="9">
        <Reference id="204182">PAL-105-0 8.1.</Reference>
      </Field>
      <Field id="13424" guid="3abf168b-62dd-4e7c-9ed6-6f8bc4ff4cff" type="4">
        <ListValues>
          <ListValue id="63031" displayName="RFC">RFC</ListValue>
        </ListValues>
      </Field>
      <Field id="13425" guid="5cf01097-8176-417a-9380-2df6aa4cf5d1" type="4">
        <ListValues>
          <ListValue id="63046" displayName="4SE">4SE</ListValue>
          <ListValue id="63050" displayName="pOP">pOP</ListValue>
        </ListValues>
      </Field>
      <Field id="13423" guid="7f8e6bff-2d88-4937-bf38-94d915c576be" type="4">
        <ListValues>
          <ListValue id="63052" displayName="Sales">Sales</ListValue>
        </ListValues>
      </Field>
      <Field id="13473" guid="c108a853-6ff6-4889-a24a-3a9564cc575b" type="8">
        <Users>
          <User id="17995" firstName="Sal" lastName="Knoffler" domain="CORP">o84654</User>
        </Users>
      </Field>
      <Field id="13474" guid="75556190-a482-411e-af1f-7259fd4c3d7f" type="8">
        <Users>
          <User id="16471" firstName="Ellen" lastName="Berkin" domain="main">c564654</User>
        </Users>
      </Field>
      <Field id="13475" guid="4dabb23d-c818-470e-aeac-db854fb0844c" type="8">
        <Users>
          <User id="3480" firstName="Peter" lastName="Griffin" domain="main">c654654</User>
        </Users>
      </Field>
    </Record>
    <Record contentId="316586" levelId="181" levelGuid="eb9b5a20-27af-4dc8-bb6b-1a9806d5fa58" moduleId="388" parentId="0">
      <Field id="13420" guid="0755d891-7926-4489-a7e8-bdc64eda8738" type="9">
        <Reference id="204181">pAL-1405-0 1.</Reference>
      </Field>
      <Field id="13424" guid="3abf168b-62dd-4e7c-9ed6-6f8bc4ff4cff" type="4">
        <ListValues>
          <ListValue id="63031" displayName="RFC">RFC</ListValue>
        </ListValues>
      </Field>
      <Field id="13425" guid="5cf01097-8176-417a-9380-2df6aa4cf5d1" type="4">
        <ListValues>
          <ListValue id="63045" displayName="pOP">pOP</ListValue>
        </ListValues>
      </Field>
      <Field id="13423" guid="7f8e6bff-2d88-4937-bf38-94d915c576be" type="4">
        <ListValues>
          <ListValue id="63053" displayName="sales">sales</ListValue>
        </ListValues>
      </Field>
      <Field id="13473" guid="c108a853-6ff6-4889-a24a-3a9564cc575b" type="8">
        <Users>
          <User id="193" firstName="John (Local)" lastName="Arkin">dardkin</User>
        </Users>
      </Field>
      <Field id="13474" guid="75556190-a482-411e-af1f-7259fd4c3d7f" type="8">
        <Users>
          <User id="16471" firstName="Nancy" lastName="Fleming" domain="main">f8979</User>
        </Users>
      </Field>
      <Field id="13475" guid="4dabb23d-c818-470e-aeac-db854fb0844c" type="8">
        <Users>
          <User id="20463" firstName="Sample" lastName="User">sample_user</User>
        </Users>
      </Field>
    </Record>
    <Field id="13390" guid="e81f29db-b394-4291-b7ba-4186cf3552fe" type="6">565593</Field>
    <Field id="13393" guid="50b870c8-3a98-49a9-b96f-32403b1fc4b5" type="4">
      <ListValues>
        <ListValue id="63698" displayName="Data Submission">Data Submission</ListValue>
      </ListValues>
    </Field>
    <Field id="13408" guid="db266517-ac2c-45a4-9479-17712b885a34" type="8">
      <Users>
        <User id="194" firstName="Zorro" lastName="Tonto">c654564</User>
      </Users>
    </Field>
    <Field id="13394" guid="66f63799-1a00-49ab-8190-e0d1a88640c9" type="1">3 Coordinators, 3 Requirements</Field>
    <Field id="13947" guid="683d5199-43d1-43c0-b8e6-38c2dcb84125" type="1">&lt;p&gt;This should generate 3 coordinator tasks with 1 req each&lt;/p&gt;</Field>
    <Field id="14054" guid="8dd17c8d-35a8-46b1-8344-3cceb1a8e386" type="3">9/30/2013 12:00:00 AM</Field>
    <Field id="14434" guid="eef81f9c-bddd-4788-af73-a2019312edf5" type="3">9/30/2013 12:00:00 AM</Field>
  </Record>
</Records>

XSLT:(更新以反映嵌套应用模板中设置的缺失模式)

   <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:ext="http://exslt.org/common"
xmlns:ns0="http://www.archer-tech.com/" exclude-result-prefixes="ns0" version="2.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>

 <xsl:variable name ="fields" select="//Metadata/FieldDefinitions" />


    <xsl:variable name="firstPassResult">
      <xsl:apply-templates select="/" mode="pass1"/>
    </xsl:variable>

    <xsl:template match="/">
      <xsl:apply-templates select="$firstPassResult" mode="pass2"/>
    </xsl:template>  


  <!--match the root node-->
  <xsl:template match="Records"  mode="pass1">
    <ArcherRecords >
      <xsl:apply-templates select="Record" mode="pass1"/>
    </ArcherRecords>
  </xsl:template>

  <!--match record nodes and put in the id field-->
  <xsl:template match="Record"  mode="pass1">
    <ArcherRecord>
      <xsl:apply-templates select="@id" mode="pass1"/>
      <xsl:apply-templates select="Field" mode="pass1"/>
      <xsl:apply-templates select="Record" mode="pass1"/>
    </ArcherRecord>
  </xsl:template>

  <!--get field name-->
  <xsl:template name="getName">
      <xsl:param name="fieldId" />
    <xsl:choose>
      <xsl:when test="$fields/FieldDefinition[@id=$fieldId]">
        <xsl:value-of select="$fields/FieldDefinition[@id=$fieldId]/@alias"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="'Field_'"/>
        <xsl:value-of select="translate(@id, ': ', '__')" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- match child relationships -->
  <xsl:template match="Record/Record"  mode="pass1">
    <xsl:variable name="fieldName" select="translate(@levelId, ': ', '__')" />
    <xsl:element name="Relationship_{$fieldName}">
      <xsl:apply-templates select="@contentId" mode="pass1"/>
      <xsl:apply-templates select="Field" mode="pass1"/>
      <xsl:apply-templates select="Record" mode="pass1"/>
    </xsl:element>
  </xsl:template>

  <!--match basic field types-->
  <xsl:template match="Field[@type='1' or @type='2' or @type='3' or @type='6' or @type='19' or @type='20' or @type='21' or @type='22']"   mode="pass1">
    <xsl:variable name="fieldName">
      <xsl:call-template name="getName">
        <xsl:with-param name="fieldId" select="@id" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:element name="{$fieldName}">
      <xsl:if test=". = ''">
        <xsl:attribute name="nil" namespace="http://www.w3.org/2001/XMLSchema-instance">true</xsl:attribute>
      </xsl:if>
      <xsl:if test=".">
        <xsl:value-of select="."/>
      </xsl:if>
    </xsl:element>
  </xsl:template>

  <!--values list field type-->
  <xsl:template match="Field[@type='4']"   mode="pass1">
    <xsl:variable name="fieldName">
      <xsl:call-template name="getName">
        <xsl:with-param name="fieldId" select="@id" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:for-each select="ListValues/ListValue">
      <xsl:element name="{$fieldName}">
        <Item>
          <xsl:value-of select="@displayName" />
        </Item>
      </xsl:element>
    </xsl:for-each>
    <xsl:if test="OtherText">
      <xsl:element name="{$fieldName}_OtherText">
        <Item>
          <xsl:value-of select="OtherText" />
        </Item>
      </xsl:element>
    </xsl:if>
  </xsl:template>

  <!--tech version and technology field types-->
  <xsl:template match="Field[@type='5' or @type='10']"   mode="pass1">
    <xsl:variable name="fieldName">
      <xsl:call-template name="getName">
        <xsl:with-param name="fieldId" select="@id" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:for-each select=". | MultiValue" >
      <xsl:element name="{$fieldName}">
        <xsl:if test="@techName">
          <TechName>
            <xsl:value-of select="@techName"/>
          </TechName>
        </xsl:if>
        <xsl:if test="@techVersionDesc">
          <TechVersionDesc>
            <xsl:value-of select="@techVersionDesc"/>
          </TechVersionDesc>
        </xsl:if>
        <xsl:if test="@techID">
          <TechID>
            <xsl:value-of select="@techID"/>
          </TechID>
        </xsl:if>
        <xsl:if test="@techVersionID">
          <TechVersionID>
            <xsl:value-of select="@techVersionID"/>
          </TechVersionID>
        </xsl:if>
        <xsl:if test="@vendorName">
          <VendorName>
            <xsl:value-of select="@vendorName"/>
          </VendorName>
        </xsl:if>
        <xsl:if test="@vendorId">
          <VendorId>
            <xsl:value-of select="@vendorId"/>
          </VendorId>
        </xsl:if>
      </xsl:element>
    </xsl:for-each>
  </xsl:template>

  <!--external link field type-->
  <xsl:template match="Field[@type='7']"  mode="pass1">
    <xsl:variable name="fieldName">
      <xsl:call-template name="getName">
        <xsl:with-param name="fieldId" select="@id" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:for-each select="Link">
      <xsl:element name="{$fieldName}">
        <Name>
          <xsl:value-of select="." />
        </Name>
        <Url>
          <xsl:value-of select="@url" />
        </Url>
      </xsl:element>
    </xsl:for-each>
  </xsl:template>

  <!--user/group and record permission field types-->
  <xsl:template match="Field[@type='8' or @type='15']"   mode="pass1">
    <xsl:variable name="fieldName">
      <xsl:call-template name="getName">
        <xsl:with-param name="fieldId" select="@id" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:for-each select="Groups/Group" >
      <xsl:element name="{$fieldName}">
        <Item>
          <xsl:value-of select="." />
        </Item>
      </xsl:element>
    </xsl:for-each>
    <xsl:for-each select="Users/User" >
      <xsl:element name="{$fieldName}">
        <Item>
          <xsl:value-of select="." />
          <xsl:if test="@domain and @domain != ''">
            <xsl:text>@</xsl:text>
            <xsl:value-of select="@domain"/>
          </xsl:if>
        </Item>
      </xsl:element>
    </xsl:for-each>
  </xsl:template>

  <!-- matrix fields -->
  <xsl:template match="Field[@type='16']"   mode="pass1">
    <xsl:variable name="fieldName">
      <xsl:call-template name="getName">
        <xsl:with-param name="fieldId" select="@id" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:for-each select="Cell">
      <xsl:element name="{$fieldName}">
        <Row>
          <xsl:value-of select="RowValue" />
        </Row>
        <Column>
          <xsl:value-of select="ColumnValue" />
        </Column>
      </xsl:element>
    </xsl:for-each>
  </xsl:template>

  <!-- images and attachments -->
  <xsl:template match="Field[@type='11' or @type='12']"   mode="pass1">
    <xsl:variable name="fieldName">
      <xsl:call-template name="getName">
        <xsl:with-param name="fieldId" select="@id" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:for-each select="File">
      <xsl:element name="{$fieldName}">
        <Item>
          <xsl:value-of select="." />
        </Item>
      </xsl:element>
    </xsl:for-each>
  </xsl:template>

  <!-- reference field types cross ref, internal ref, related record -->
  <xsl:template match="Field[@type='9' or @type='18' or @type='23']"  mode="pass1">
    <xsl:variable name="fieldName">
      <xsl:call-template name="getName">
        <xsl:with-param name="fieldId" select="@id" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:for-each select="Reference">
      <xsl:element name="{$fieldName}">
        <xsl:variable name="record" select="../../Record[@contentId = current()/@id]" />
        <xsl:choose>
          <xsl:when test="$record">
            <xsl:apply-templates select="$record/@id" mode="pass1"/>
            <xsl:apply-templates select="$record/Field"  mode="pass1"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates select="@id" mode="pass1"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:element>
    </xsl:for-each>
  </xsl:template>

  <!-- reference field types subform -->
  <xsl:template match="Field[@type='24']"  mode="pass1">
    <xsl:variable name="fieldName">
      <xsl:call-template name="getName">
        <xsl:with-param name="fieldId" select="@id" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:for-each select="Subform">
      <xsl:element name="{$fieldName}">
        <xsl:element name="Field_id">
          <xsl:value-of select="@contentId"/>
        </xsl:element>
        <xsl:apply-templates select="Field" mode="pass1"/>
      </xsl:element>
    </xsl:for-each>
  </xsl:template>

  <!-- multi reference field types -->
  <xsl:template match="Field[@type='27']"  mode="pass1">
    <xsl:variable name="fieldName">
      <xsl:call-template name="getName">
        <xsl:with-param name="fieldId" select="@id" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:for-each select="MultiReference">
      <xsl:element name="{$fieldName}">
        <Item>
          <xsl:apply-templates select="." mode="pass1" />
        </Item>
      </xsl:element>
    </xsl:for-each>
  </xsl:template>

  <!--match all attributes and write them as a field-->
  <xsl:template match="@*" mode="pass1">
    <xsl:element name="Field_{translate(name(), ': ', '__')}">
      <xsl:value-of select="."/>
    </xsl:element>
  </xsl:template>


<!-- XSL that transforms the Generic Report Transform Output to the CMEP output we need -->
    <xsl:template match="/ns0:ArcherRecords" mode="pass2">
        <ArcherRecords xmlns="http://www.archer-tech.com/">
            <xsl:for-each select="ns0:ArcherRecord">
                <xsl:for-each select="ns0:Relationship_181">
                <ArcherRecord>
                        <Tracking_ID>
                            <xsl:value-of select="../ns0:Tracking_ID"></xsl:value-of>
                        </Tracking_ID>
                        <CMEP_Type>
                            <xsl:value-of select="../ns0:CMEP_Type"></xsl:value-of>
                        </CMEP_Type>
                        <Reg_Svcs_Contact>
                            <xsl:value-of select="../ns0:Reg_Svcs_Contact"></xsl:value-of>
                        </Reg_Svcs_Contact>
                        <Title>
                            <xsl:value-of select="../ns0:Title"></xsl:value-of>
                        </Title>
                        <Description>
                            <xsl:value-of select="../ns0:Description"></xsl:value-of>
                        </Description>
                        <Next_Processing__Internal_Due_Date>
                            <xsl:value-of select="../ns0:Next_Processing__Internal_Due_Date"></xsl:value-of>
                        </Next_Processing__Internal_Due_Date>
                        <Next_Processing__External_Due_Date>
                            <xsl:value-of select="../ns0:Next_Processing__External_Due_Date"></xsl:value-of>
                        </Next_Processing__External_Due_Date>
                        <BU_Coordinator>
                            <xsl:value-of select="../ns0:Relationship_181/ns0:BU_Coordinator"></xsl:value-of>
                        </BU_Coordinator>
                        <Assignment>
                            <Field_contentId>
                                <xsl:value-of select="ns0:Field_contentId"></xsl:value-of>
                            </Field_contentId>
                            <Requirements>
                                <xsl:for-each select="ns0:Requirements/ns0:Field_id">
                                    <Field_id>
                                        <xsl:value-of select="."/>
                                    </Field_id>
                                </xsl:for-each>
                            </Requirements>
                            <Region__Reg_Entity>
                                <xsl:for-each select="ns0:Relationship_181/ns0:Requirement_Owner/ns0:Item">
                                    <Item>
                                        <xsl:value-of select="."/>
                                    </Item>
                                </xsl:for-each>
                            </Region__Reg_Entity>
                            <xsl:for-each select="ns0:Function">
                                <Function>
                                    <xsl:for-each select="ns0:Item">
                                        <Item>
                                            <xsl:value-of select="."/>
                                        </Item>
                                    </xsl:for-each>
                                </Function>
                            </xsl:for-each>
                            <Business_Unit>
                                    <Item>
                                        <xsl:value-of select="ns0:Business_Unit"></xsl:value-of>
                                    </Item>
                            </Business_Unit>
                            <BU_Coordinator>
                                    <Item>
                                        <xsl:value-of select="ns0:BU_Coordinator"></xsl:value-of>
                                    </Item>
                            </BU_Coordinator>
                            <Requirement_Owner>
                                    <Item>
                                        <xsl:value-of select="ns0:Requirement_Owner"></xsl:value-of>
                                    </Item>
                            </Requirement_Owner>
                            <xsl:for-each select="ns0:SMEs">
                                <SMEs>
                                    <xsl:for-each select="ns0:Item">
                                        <Item>
                                            <xsl:value-of select="."/>
                                        </Item>
                                    </xsl:for-each>
                                </SMEs>
                            </xsl:for-each>
                        </Assignment>
                    </ArcherRecord>
                </xsl:for-each>
            </xsl:for-each>
        </ArcherRecords>
    </xsl:template>
</xsl:stylesheet>

所需的输出 XML:

<?xml version="1.0" encoding="utf-8"?>
<ArcherRecords xmlns="http://www.archer-tech.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ArcherRecord>
    <Tracking_ID>565593</Tracking_ID>
    <CMEP_Type>
      <Item>Data Submission</Item>
    </CMEP_Type>
    <Reg_Svcs_Contact>
      <Item>c654654</Item>
    </Reg_Svcs_Contact>
    <Title>3 Coordinators, 3 Requirements</Title>
    <Description>&lt;p&gt;This should generate 3 coordinator tasks with 1 req each&lt;/p&gt;</Description>
    <Next_Processing__Internal_Due_Date>9/30/2013 12:00:00 AM</Next_Processing__Internal_Due_Date>
    <Next_Processing__External_Due_Date>9/30/2013 12:00:00 AM</Next_Processing__External_Due_Date>
    <Assignment>
      <Field_contentId>316580</Field_contentId>
      <Requirements>
        <Field_id>204182</Field_id>
      </Requirements>
      <Region__Reg_Entity>
        <Item>RFC</Item>
      </Region__Reg_Entity>
      <Function>
        <Item>GOP</Item>
      </Function>
      <Business_Unit>
        <Item>sales</Item>
      </Business_Unit>
      <BU_Coordinator>
        <Item>c654654@main</Item>
      </BU_Coordinator>
      <Requirement_Owner>
        <Item>r65464@main</Item>
      </Requirement_Owner>
      <SMEs>
        <Item>c654654@main</Item>
      </SMEs>
    </Assignment>
  </ArcherRecord>
  <ArcherRecord>
    <Tracking_ID>565593</Tracking_ID>
    <CMEP_Type>
      <Item>Data Submission</Item>
    </CMEP_Type>
    <Reg_Svcs_Contact>
      <Item>c654654</Item>
    </Reg_Svcs_Contact>
    <Title>3 Coordinators, 3 Requirements</Title>
    <Description>&lt;p&gt;This should generate 3 coordinator tasks with 1 req each&lt;/p&gt;</Description>
    <Next_Processing__Internal_Due_Date>9/30/2013 12:00:00 AM</Next_Processing__Internal_Due_Date>
    <Next_Processing__External_Due_Date>9/30/2013 12:00:00 AM</Next_Processing__External_Due_Date>
    <Assignment>
      <Field_contentId>316581</Field_contentId>
      <Requirements>
        <Field_id>204182</Field_id>
      </Requirements>
      <Region__Reg_Entity>
        <Item>RFC</Item>
      </Region__Reg_Entity>
      <Function>
        <Item>LSE</Item>
      </Function>
      <Function>
        <Item>pOP</Item>
      </Function>
      <Business_Unit>
        <Item>Sales</Item>
      </Business_Unit>
      <BU_Coordinator>
        <Item>v654564@main</Item>
      </BU_Coordinator>
      <Requirement_Owner>
        <Item>r65464@main</Item>
      </Requirement_Owner>
      <SMEs>
        <Item>c654654@main</Item>
      </SMEs>
    </Assignment>
  </ArcherRecord>
  <ArcherRecord>
    <Tracking_ID>565593</Tracking_ID>
    <CMEP_Type>
      <Item>Data Submission</Item>
    </CMEP_Type>
    <Reg_Svcs_Contact>
      <Item>c654654</Item>
    </Reg_Svcs_Contact>
    <Title>3 Coordinators, 3 Requirements</Title>
    <Description>&lt;p&gt;This should generate 3 coordinator tasks with 1 req each&lt;/p&gt;</Description>
    <Next_Processing__Internal_Due_Date>9/30/2013 12:00:00 AM</Next_Processing__Internal_Due_Date>
    <Next_Processing__External_Due_Date>9/30/2013 12:00:00 AM</Next_Processing__External_Due_Date>
    <Assignment>
      <Field_contentId>316586</Field_contentId>
      <Requirements>
        <Field_id>204181</Field_id>
      </Requirements>
      <Region__Reg_Entity>
        <Item>RFC</Item>
      </Region__Reg_Entity>
      <Function>
        <Item>pOP</Item>
      </Function>
      <Business_Unit>
        <Item>sales</Item>
      </Business_Unit>
      <BU_Coordinator>
        <Item>coihgriggin</Item>
      </BU_Coordinator>
      <Requirement_Owner>
        <Item>r65464@main</Item>
      </Requirement_Owner>
      <SMEs>
        <Item>sample_user</Item>
      </SMEs>
    </Assignment>
  </ArcherRecord>
</ArcherRecords>
4

1 回答 1

1

Modes are not "sticky". If you're in a template with mode="pass1" you still need an explicit mode="pass1" or mode="#current" on any apply-templates in order to keep looking for templates in that mode. If you don't specify a mode attribute then it will try and apply templates in the default mode. For example in

  <!--match the root node-->
  <xsl:template match="Records"  mode="pass1">
    <ArcherRecords >
      <xsl:apply-templates select="Record" />
    </ArcherRecords>
  </xsl:template>

the apply-templates will look for an <xsl:template match="Record"> that has no mode, and in particular it won't find

  <xsl:template match="Record"  mode="pass1">
    <ArcherRecord>
      <xsl:apply-templates select="@id" />
      <xsl:apply-templates select="Field" />
      <xsl:apply-templates select="Record" />
    </ArcherRecord>
  </xsl:template>

(and so on).

Edit: Now you've fixed this I see the other problem - your pass2 templates use ns0:... to operate on elements in the http://www.archer-tech.com/ namespace, but the way you're creating your pass 1 elements means that they are not in any namespace. So your

<xsl:template match="/ns0:ArcherRecords" mode="pass2">

doesn't match anything, and the default built-in template rules are used instead. The easiest way to fix this is to add

xmlns="http://www.archer-tech.com/"

to the <xsl:stylesheet> element, or alternatively remove all the uses of ns0: in your pass 2 select and match expressions.

P.S. you can also remove the xmlns:ext declaration as you're not using it anywhere (and even if you were it probably wouldn't be necessary in XSLT 2.0).

P.P.S. a useful trick when you're doing two passes like this is to dump the first pass result for debugging purposes, e.g.

<xsl:template match="/">
  <debug>
    <xsl:copy-of select="$firstPassResult" />
    <xsl:apply-templates select="$firstPassResult" mode="pass2"/>
  </debug>
</xsl:template>

you can remove the wrapping element and the copy-of once you've got it all working.

于 2013-08-20T16:15:37.210 回答