我想用点标记化值检查输入属性值

时间:2014-09-30 17:47:11

标签: xml xslt xpath xslt-2.0

我试图查看输入objectType和value0是否存在于Types / Type中并检查条件并使用输出xml中Types / Type的兄弟属性名称值。 这是输入xml:

<?xml version="1.0" encoding="UTF-8"?>
<outPut>
  <object>
    <objectType>TestOne</objectType>
    <Attributes>
      <attribute name="value0">codeOne</attribute>
      <attribute name="value1">35</attribute>
      <attribute name="value2">35</attribute>
    </Attributes>
    <objectType>TestTwo</objectType>
    <Attributes>
      <attribute name="value0">codeTwo</attribute>
      <attribute name="value1">25</attribute>
      <attribute name="value2">35</attribute>
    </Attributes>
    <objectType>TestThree</objectType>
    <Attributes>
      <attribute name="value0">codeThree</attribute>
      <attribute name="value1">25</attribute>
      <attribute name="value2">3225</attribute>
      <attribute name="value3">225</attribute>
    </Attributes>
    <objectType>TestFour</objectType>
    <Attributes>
      <attribute name="value0">codeFour</attribute>
      <attribute name="value1">25</attribute>
      <attribute name="value2">35</attribute>
    </Attributes>
    <objectType>TestFive</objectType>
    <Attributes>
      <attribute name="value0">codeFive</attribute>
      <attribute name="value1">2</attribute>
      <attribute name="value2">3225</attribute>
      <attribute name="value3">225</attribute>
    </Attributes>
    <objectType>TestSix</objectType>
    <Attributes>
      <attribute name="value0">codSix</attribute>
      <attribute name="value1">2</attribute>
      <attribute name="value2">3225</attribute>
      <attribute name="value3">225</attribute>
    </Attributes>
  </object>
  <Types>
    <Type>
      <temp>TestOne</temp>
      <ID>2847</ID>
      <Is_Ingest>0</Is_Ingest>
      <Category>NAV</Category>
      <CategoryTwo>NAVAid</CategoryTwo>
      <Class>codeOne</Class>
      <New_Attribute>nisting</New_Attribute>
      <New_Value>52</New_Value>
      <Condition>value1=35</Condition>
    </Type>
    <Type>
      <temp>TestTwo</temp>
      <ID>2847</ID>
      <Is_Ingest>0</Is_Ingest>
      <Category>NAV</Category>
      <CategoryTwo>NAVAid</CategoryTwo>
      <Class>codeTwo</Class>
      <New_Attribute>nisting</New_Attribute>
      <New_Value>53</New_Value>
      <Condition>value1!=33</Condition>
    </Type>
    <Types>
      <Type>
        <temp>TestThree</temp>
        <ID>28247</ID>
        <Is_Ingest>0</Is_Ingest>
        <Category>NAV</Category>
        <CategoryTwo>NAVAid</CategoryTwo>
        <Class>codeThree</Class>
        <New_Attribute>nisting</New_Attribute>
        <New_Value>52</New_Value>
        <Condition>value1=35</Condition>
      </Type>
      <Type>
        <temp>TestFour</temp>
        <ID>2847</ID>
        <Is_Ingest>0</Is_Ingest>
        <Category>NAV</Category>
        <CategoryTwo>NAVAid</CategoryTwo>
        <Class>codeFour</Class>
        <New_Attribute>AidM</New_Attribute>
        <New_Value>45</New_Value>
        <Condition>value1!=33 & value1!=28</Condition>
      </Type>
      <Type>
        <temp>TestFive</temp>
        <ID>2847</ID>
        <Is_Ingest>0</Is_Ingest>
        <Category>NAV</Category>
        <CategoryTwo>Aid</CategoryTwo>
        <Class>codeFive</Class>
        <New_Attribute>AidM</New_Attribute>
        <New_Value>4</New_Value>
        <Condition>!value</Condition>
      </Type>
      <Type>
        <temp>TestSix</temp>
        <ID>2847</ID>
        <Is_Ingest>0</Is_Ingest>
        <Category>NAV</Category>
        <CategoryTwo>Aid</CategoryTwo>
        <Class>codeSix</Class>
        <New_Attribute>AidM</New_Attribute>
        <New_Value>4</New_Value>
      </Type>
    </Types>
  </outPut>

这是xsl

<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:strip-space elements="*"/>
    <xsl:template match="/Input">
        <objects>
            <xsl:for-each select="Output">
                <object type="{object/objectType}">
                    <xsl:variable name="attributes" select="Attributes/*"/>
                    <xsl:variable name="matching-template" select="/Output/Types/Type[temp=$attributes and class=$attributes]"/>
                    <template>
                        <xsl:value-of select="$matching-template/New_Attribute"/>
                        <xsl:value-of select="$matching-template/New_Value"/>
                    </template>
                </object>
            </xsl:for-each>
        </objects>
    </xsl:template>
</xsl:stylesheet>

预期产出

<output>
    <object>
        <objectType>TestOne</objectType>
        <Attributes>
            <attribute name="value0">codeOne</attribute>
            <attribute name="value1">25</attribute>
            <attribute name="value2">35</attribute>
            <attribute name="nisting">52</attribute>
        </Attributes>
        <objectType>TestTwo</objectType>
        <Attributes>
            <attribute name="value0">codeTwo</attribute>
            <attribute name="value1">25</attribute>
            <attribute name="value2">35</attribute>
            <attribute name="NAV">NAVAID</attribute>
            <attribute name="value2">35</attribute>
        </Attributes>
    </object>
</output>

0 个答案:

没有答案