xsl-list
[Top] [All Lists]

Re: [xsl] Selecting the value from diff i/p XML

2010-09-15 18:08:46
I'm not 100% sure I understand what OP wants, but the following XSLT
1.0 program generates what I think is the desired output, albeit
probably a lot less efficiently than could be done with clever keys.

Note that I couldn't bring myself to have attributes named id= that
are not xsd:ID, so I renamed it to record=.

<?xml version="1.0" encoding="UTF-8"?>
<!-- read in Root2 as input, and correlate the record= -->
<!-- of each <data> with the corresponding record= of -->
<!-- an <item> in Root1, and spit out the value= of -->
<!-- the first match -->
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

  <xsl:template match="/">
    <wrapper>
      <xsl:apply-templates select="root2/data"/>
    </wrapper>
  </xsl:template>

  <xsl:template match="data">
    <out>
      <xsl:value-of select="@record"/>
      <xsl:text>=</xsl:text>
      <xsl:value-of 
select="document('./Root1.xml')/root1/item[(_at_)record=current()/@record]/@value"/>
    </out>
  </xsl:template>

</xsl:stylesheet>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--