2016-09-28 47 views
0

我想做一個XSLT翻譯來找到使用條件的某個值。從XML的XSLT翻譯

我的XML文件片斷如下:

<?xml version="1.0" encoding="utf-8"?> 
    <?xml-stylesheet type="text/xsl" href="sample.xslt"?> 

<ValuesList> 
    <Values ID="ZLOV1FD23146" ParentID="ZLOV1GR00001" AllowUserValueAddition="true" UseValueID="false"> 
     <Name QualifierID="std.lang.all">MG1_01 USP [MPRD]</Name> 
     <Validation BaseType="text" MinValue="" MaxValue="" MaxLength="511" InputMask=""/> 
     <Language DimensionID="Language"/> 
     <ValueGroup> 
     <Value QualifierID="lang_ZPIM1ID">ABC</Value> 
     <Value QualifierID="std.lang.all">minimised recess depth enables use in ceilings with compact space</Value> 
     </ValueGroup> 
     <ValueGroup> 
     <Value QualifierID="std.lang.all">DEF</Value> 
     </ValueGroup> 
     <ValueGroup> 
     <Value QualifierID="lang_ZPIM1ID">ASD</Value> 
     <Value QualifierID="std.lang.all">qwer</Value> 
     </ValueGroup> 
     <ValueGroup> 
     <Value QualifierID="std.lang.all">FGH</Value> 
     <Value QualifierID="lang_ZPIM1ID">dfghy</Value> 
     </ValueGroup> 
     <ValueGroup> 
     <Value QualifierID="std.lang.all">RST</Value> 
     </ValueGroup> 
    </Values> 

    <Values ID="ZLOV1FDsdasda" ParentID="ZLOV1GR00002" AllowUserValueAddition="true" UseValueID="false"> 
     <Name QualifierID="std.lang.all">MG1_01 USP [MPRD]</Name> 
     <Validation BaseType="text" MinValue="" MaxValue="" MaxLength="511" InputMask=""/> 
     <Language DimensionID="Language"/>  
     <ValueGroup> 
     <Value QualifierID="lang_ZPIM1ID">ABC</Value> 
     <Value QualifierID="std.lang.all">minimised recess depth enables use in ceilings with compact space</Value> 
     </ValueGroup> 
     <ValueGroup> 
     <Value QualifierID="std.lang.all">asdas</Value> 
     </ValueGroup> 
     <ValueGroup> 
     <Value QualifierID="lang_ZPIM1ID">ASD</Value> 
     <Value QualifierID="std.lang.all">qwer</Value> 
     </ValueGroup> 
     <ValueGroup> 
     <Value QualifierID="std.lang.all">FGH</Value> 
     <Value QualifierID="lang_ZPIM1ID">dfghy</Value> 
     </ValueGroup> 
     <ValueGroup> 
     <Value QualifierID="std.lang.all">iyi</Value> 
     </ValueGroup> 
    </Values> 
</ValuesList> 

我需要,以創造sample.XSLT文件,以滿足以下條件:

  • 確定「ValueGroup」元素裏面做只有一個「值「並檢查這個值是否在上下文」std.lang.all「中。
  • 檢查語言尺寸='語言'
  • 輸出應該在值ID |值格式。 (例如,ZLOV1FD23146 | DEF)

我已經創建了XSLT文件,如下片段但不工作:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="text" indent="yes"/> 
    <xsl:strip-space elements="*"/>  
    <xsl:template match="ValuesList/Values/ValueGroup"> 
      <xsl:text> ID  | Value</xsl:text> 
      <xsl:text>&#x0A;</xsl:text> 
     <xsl:if test="count(Value)='1' and Value/@QualifierID='std.lang.all'">   
       <xsl:value-of select="concat(//Values/@ID,' |',Value,'&#x0A;')"></xsl:value-of> 
     </xsl:if> 
    </xsl:template> 
</xsl:stylesheet> 

請幫我out..Thanks提前。

回答

1

,你可以有這樣的事情:

EDITED

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="text" indent="yes"/> 
    <xsl:strip-space elements="*"/>  

    <xsl:template match="/"> 
     <xsl:text> ID  | Value</xsl:text> 
     <xsl:text>&#x0A;</xsl:text> 
     <!-- Choose the nodes you want to output here. 
      you can directly place the conditions 
      in an attribute --> 
     <xsl:apply-templates select="ValuesList/Values[Language[@DimensionID='Language']]"/> 
    </xsl:template> 

    <xsl:template match="Values"> 
     <xsl:apply-templates select="ValueGroup[count(Value)=1 and Value/@QualifierID='std.lang.all']"/> 
    </xsl:template> 

    <xsl:template match="ValueGroup"> 
     <xsl:value-of select="concat(ancestor::Values/@ID,' |',Value,'&#x0A;')"/> 
    </xsl:template> 

</xsl:stylesheet> 
+0

喬爾感謝您help..It做工作,爲單套。我試圖在內添加另一套,並且它不捕獲第二套的輸出。友善的建議。 – FirDaus

+0

請修改您的問題,說明該要求。我修改了我的答案。 –

+0

謝謝喬爾。我已經修改了我的問題。最後一個問題Joel,我在哪裏檢查'Language Dimension ='English'的條件?再次感謝喬爾。非常感謝你的幫助。 – FirDaus