tags:

views:

101

answers:

1

Hi,

I'm new XSLT but i want to be able compare to XMLs using XSL. The problem the nodes may be changed so i need to make it using lacal-name().

But i can't seem to be able to do it. Please check the below and help me thanks.

    <xsl:output method="xml" indent="yes"/>
  <xsl:param name="Doc1" select="Root/items/*" />
  <xsl:param name="Doc2" select="Root/items/*" />

  <xsl:variable name="Second" select="$Doc2/Root/items/*"/>

  <xsl:template match="/">
    <xsl:apply-templates select="$Doc1/*"/>
  </xsl:template>

  <xsl:template match="items">
    <Root>
    <xsl:for-each select="item">
      <xsl:variable name="Names" select="$Second/local-name()"/>
      <xsl:choose>
        <xsl:when test="$Names!=$Names">
          <xsl:value-of select="$Second/current()"/>
         </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="current()"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
    </Root>
  </xsl:template>
</xsl:stylesheet>
A: 

Don't know whether that is the problem but hera are at least a few ...

<xsl:param name="Doc2" select="Root/items/*" />

path is Root/items/*

<xsl:variable name="Second" select="$Doc2/Root/items/*"/>

path is Root/items/*/Root/items/*

<xsl:variable name="Names" select="$Second/local-name()"/>

and there you are now saying get the local name for every item in the node set `Root/items/*/Root/items/*.

Then in

<xsl:when test="$Names!=$Names">

you compare the retrieved list of names to the retrieved list of names and do something if these values (which are the same) should be not equal.

To further answer your question it would be helpful to see how the original documents look like. Furthermore, how are you passing the nodes into the xlt? And, if the names of the elements are not uniqe in each of the documents, Root/items/*/local-name() does return a node list not a singel node (effectively you are saying give me the local-names for all items under Root/items).

Obalix