Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于每个函数的XML XSLT_Xslt - Fatal编程技术网

用于每个函数的XML XSLT

用于每个函数的XML XSLT,xslt,Xslt,我将输入XML作为 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <document> <item> <UID>1000909090</UID> <functionalName lang="en">Filter</functionalName> <functionalName lang="hin"&

我将输入XML作为

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<document>
<item>
              <UID>1000909090</UID>
    <functionalName lang="en">Filter</functionalName>
    <functionalName lang="hin">Filter1</functionalName>
    <functionalName lang="en">Filter2</functionalName>
    <functionalName lang="hin">Filter3</functionalName>
</item>
<item>
         <UID>1000909091</UID>
    <functionalName lang="en">Filter4</functionalName>
    <functionalName lang="chi">Filter5</functionalName>
    <functionalName lang="en">Filter6</functionalName>
</item>
</document>
我想循环使用每种语言的标记functionalName来捕获值。对于每种特定语言,输出需要存储在元素值_MVL中。 第一个UID 1000909090的输出XML的代码段应为en

 <MultiValueAttribute name="VALUE_MVL">
           <ValueList>
              <Value>Filter</Value>
              <Value>Filter2</Value>
           </ValueList>
 </MultiValueAttribute>
下面提到了所需的输出XML

预期输出完整XML

 <?xml version="1.0" encoding="UTF-8"?>
<CatalogItem>
 <Body>
  <CatalogItem key="FUNCTIONALNAME_MVL-1000909090-en">
     <MasterCatalog>
        <RevisionID>
           <BaseName>FUNCTIONALNAME_MVL</BaseName>
           <Version />
           <DBID />
        </RevisionID>
     </MasterCatalog>
     <ItemData>
        <Attribute name="PRODUCTID">
           <Value>1000909090</Value>
        </Attribute>
        <Attribute name="PRODUCTIDEXT">
           <Value>en</Value>
        </Attribute>
        <MultiValueAttribute name="VALUE_MVL">
           <ValueList>
              <Value>Filter</Value>
              <Value>Filter2</Value>
           </ValueList>
        </MultiValueAttribute>
     </ItemData>
     <RelationshipData>
        <Relationship>
           <RelationType>FUNCTIONALNAME_MVL_Item_Master</RelationType>
           <RelatedItems count="1">
              <RelatedItem referenceKey="1000909090" />
           </RelatedItems>
        </Relationship>
     </RelationshipData>
  </CatalogItem>
  <CatalogItem key="FUNCTIONALNAME_MVL-1000909090-hin">
     <MasterCatalog>
        <RevisionID>
           <BaseName>FUNCTIONALNAME_MVL</BaseName>
           <Version />
           <DBID />
        </RevisionID>
     </MasterCatalog>
     <ItemData>
        <Attribute name="PRODUCTID">
           <Value>1000909090</Value>
        </Attribute>
        <Attribute name="PRODUCTIDEXT">
           <Value>hin</Value>
        </Attribute>
        <MultiValueAttribute name="VALUE_MVL">
           <ValueList>
              <Value>Filter1</Value>
              <Value>Filter3</Value>
           </ValueList>
        </MultiValueAttribute>
     </ItemData>
     <RelationshipData>
        <Relationship>
           <RelationType>FUNCTIONALNAME_MVL_Item_Master</RelationType>
           <RelatedItems count="1">
              <RelatedItem referenceKey="1000909090" />
           </RelatedItems>
        </Relationship>
     </RelationshipData>
  </CatalogItem>
   </Body>
   <Body>
   <CatalogItem key="FUNCTIONALNAME_MVL-1000909091-en">
     <MasterCatalog>
        <RevisionID>
           <BaseName>FUNCTIONALNAME_MVL</BaseName>
           <Version />
           <DBID />
        </RevisionID>
     </MasterCatalog>
     <ItemData>
        <Attribute name="PRODUCTID">
           <Value>1000909091</Value>
        </Attribute>
        <Attribute name="PRODUCTIDEXT">
           <Value>en</Value>
        </Attribute>
        <MultiValueAttribute name="VALUE_MVL">
           <ValueList>
              <Value>Filter4</Value>
              <Value>Filter6</Value>
           </ValueList>
        </MultiValueAttribute>
     </ItemData>
     <RelationshipData>
        <Relationship>
           <RelationType>FUNCTIONALNAME_MVL_Item_Master</RelationType>
           <RelatedItems count="1">
              <RelatedItem referenceKey="1000909091" />
           </RelatedItems>
        </Relationship>
     </RelationshipData>
   </CatalogItem>
   <CatalogItem key="FUNCTIONALNAME_MVL-1000909091-chi">
     <MasterCatalog>
        <RevisionID>
           <BaseName>FUNCTIONALNAME_MVL</BaseName>
           <Version />
           <DBID />
        </RevisionID>
     </MasterCatalog>
     <ItemData>
        <Attribute name="PRODUCTID">
           <Value>1000909091</Value>
        </Attribute>
        <Attribute name="PRODUCTIDEXT">
           <Value>chi</Value>
        </Attribute>
        <MultiValueAttribute name="VALUE_MVL">
           <ValueList>
              <Value>Filter5</Value>
           </ValueList>
        </MultiValueAttribute>
     </ItemData>
     <RelationshipData>
        <Relationship>
           <RelationType>FUNCTIONALNAME_MVL_Item_Master</RelationType>
           <RelatedItems count="1">
              <RelatedItem referenceKey="1000909091" />
           </RelatedItems>
        </Relationship>
     </RelationshipData>
  </CatalogItem>
 </Body>
 </CatalogItem>
我使用XSLT,但它不适用于VALUE\u MVL标记。好心帮忙

<xsl:stylesheet 
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes"/>

<xsl:key name="functional" match="functionalName" use="concat(generate-id(..), '|', @lang)" />  

   <xsl:template match="document"> 
<CatalogItem>
<xsl:for-each select="item">
<Body>    
<xsl:for-each select="functionalName[generate-id() = generate-id(key('functional', concat  (generate-id(..), '|', @lang))[1])]"> 
<CatalogItem>
<xsl:attribute name="key">
<xsl:value-of select="concat('FUNCTIONALNAME_MVL','-',ancestor::item/UID,'-',@lang)"/>                                                  
</xsl:attribute>
<MasterCatalog>
    <RevisionID>
        <BaseName>FUNCTIONALNAME_MVL</BaseName>
        <Version/>
        <DBID/>
    </RevisionID>
</MasterCatalog>
<ItemData>
    <Attribute name="PRODUCTID">
        <Value>
            <xsl:value-of select="ancestor::item/UID"/>
        </Value>
    </Attribute>
    <Attribute name="PRODUCTIDEXT">
        <Value>
            <xsl:value-of select="@lang"/>
        </Value>
    </Attribute>                                                
    <MultiValueAttribute>
        <xsl:attribute name="name">VALUE_MVL</xsl:attribute>
        <ValueList>         
            <xsl:for-each select=".">                                               
                <Value>
        <xsl:value-of select="../functionalName"/> 
                </Value>
            </xsl:for-each>
        </ValueList>
    </MultiValueAttribute>
</ItemData>
<RelationshipData>
    <Relationship>
        <RelationType>FUNCTIONALNAME_MVL_Item_Master</RelationType>
        <RelatedItems>
            <xsl:attribute name="count">1</xsl:attribute>
            <RelatedItem>
                <xsl:attribute name="referenceKey">
            <xsl:value-of select="ancestor::item/UID"/>
                </xsl:attribute>
            </RelatedItem>
        </RelatedItems>
    </Relationship>
</RelationshipData>
 </CatalogItem>
 </xsl:for-each>
 </Body>          
 </xsl:for-each>
 </CatalogItem>
 </xsl:template> 
 </xsl:stylesheet>

我已经在共享XSLT中添加了变量UID和Lang,并使用它们来过滤所需的“functionalName”结果。请查看并检查输出:

<xsl:stylesheet 
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output indent="yes"/>

  <xsl:key name="functional" match="functionalName" use="concat(generate-id(..), '|', @lang)" />  

  <xsl:template match="document"> 
    <CatalogItem>
      <xsl:for-each select="item">
        <Body>    
          <xsl:for-each select="functionalName[generate-id() = generate-id(key('functional', concat  (generate-id(..), '|', @lang))[1])]"> 
            <xsl:variable name="UID" select="ancestor::item/UID"/>
            <xsl:variable name="Lang" select="@lang"/>
            <CatalogItem>
              <xsl:attribute name="key">
                <xsl:value-of select="concat('FUNCTIONALNAME_MVL','-',ancestor::item/UID,'-',@lang)"/>                                                  
              </xsl:attribute>
              <MasterCatalog>
                <RevisionID>
                  <BaseName>FUNCTIONALNAME_MVL</BaseName>
                  <Version/>
                  <DBID/>
                </RevisionID>
              </MasterCatalog>
              <ItemData>
                <Attribute name="PRODUCTID">
                  <Value>
                    <xsl:value-of select="ancestor::item/UID"/>
                  </Value>
                </Attribute>
                <Attribute name="PRODUCTIDEXT">
                  <Value>
                    <xsl:value-of select="@lang"/>
                  </Value>
                </Attribute>                                                
                <MultiValueAttribute>
                  <xsl:attribute name="name">VALUE_MVL</xsl:attribute>
                  <ValueList>
                    <xsl:message><xsl:value-of select="$Lang"/></xsl:message>
                    <xsl:message><xsl:value-of select="$UID"/></xsl:message>
                    <xsl:for-each select="parent::item/functionalName[parent::item/UID=$UID and @lang=$Lang]">                                               
                      <Value>
                        <xsl:value-of select="text()"/> 
                      </Value>
                    </xsl:for-each>
                  </ValueList>
                </MultiValueAttribute>
              </ItemData>
              <RelationshipData>
                <Relationship>
                  <RelationType>FUNCTIONALNAME_MVL_Item_Master</RelationType>
                  <RelatedItems>
                    <xsl:attribute name="count">1</xsl:attribute>
                    <RelatedItem>
                      <xsl:attribute name="referenceKey">
                        <xsl:value-of select="ancestor::item/UID"/>
                      </xsl:attribute>
                    </RelatedItem>
                  </RelatedItems>
                </Relationship>
              </RelationshipData>
            </CatalogItem>
          </xsl:for-each>
        </Body>          
      </xsl:for-each>
    </CatalogItem>
  </xsl:template> 
</xsl:stylesheet>
试着替换

<xsl:for-each select=".">
  <Value>
    <xsl:value-of select="../functionalName"/>
  </Value>
</xsl:for-each>

<xsl:for-each select="../functionalName[@lang=current()/@lang]">
  <Value>
    <xsl:value-of select="."/>
  </Value>
</xsl:for-each>