1

I was trying to see if the input objectType and value0 exists in the Types/Type and check the condition and use the sibling attribute name value of the Types/Type in the output xml. Here is the input 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>

Here is the 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>

the expected output

<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>
i alarmed alien
  • 9,412
  • 3
  • 27
  • 40
  • I'm afraid this is a little erratic. Could you, please, a) tidy up your input XML, b) describe in more detail what you would like to achieve and c) add more content to your XSLT than just variable definitions. We need to see at least a template or a for-each definition. – Marcus Rickert Sep 30 '14 at 19:32
  • You input xml is not well formed. Please correct this. – PhillyNJ Sep 30 '14 at 20:44
  • couldn't evaluate ! | != = and & characters – user4071541 Sep 30 '14 at 21:38

0 Answers0