xsl-list
[Top] [All Lists]

SV: [xsl] Help needed to transform in data joining

2006-11-03 05:11:19
Hi Ghota,
I was just wondering if you wanted to check the existence of data within
each SBSaddress element? If so the following modification will _merge_ the
two inputs:

  <xsl:template match="ADDRESS">
    <ADDRESS>
      <xsl:variable name="this-id" select="@id"/>
      <xsl:attribute name="id" select="$this-id"/>
      <xsl:for-each select="*">
        <xsl:choose>
          <xsl:when
test="normalize-space(/root/c/addresslists/SBSaddress_[(_at_)id =
$this-id]/*[name()=current()/name()])">
            <xsl:copy-of select="/root/c/addresslists/SBSaddress_[(_at_)id =
$this-id]/*[name()=current()/name()]"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:copy-of select="."/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </ADDRESS>
  </xsl:template>

producing the following result:
        ...
        <ADDRESS id="2">
                <State>KY</State>
                <Address1>campbellcounty</Address1>
                <Address2>bananacounty</Address2>
                <City>fortthomas</City>
                <Country>UnitedStates</Country>
                <Province>--Select--</Province>
                <ZipCode>11</ZipCode>
                <County />
        </ADDRESS>

Just in case this is what you want!

 - Per Osnes. 




-----Opprinnelig melding-----
Fra: cknell(_at_)onebox(_dot_)com [mailto:cknell(_at_)onebox(_dot_)com] 
Sendt: 2. november 2006 16:52
Til: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Emne: RE: [xsl] Help needed to transform in data joining

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

    <xsl:template match="/">
        <xsl:apply-templates />
    </xsl:template>

    <xsl:template match="root">
      <root>
        <xsl:apply-templates select="A" />
      </root>
    </xsl:template>

    <xsl:template match="A">
      <A>
        <xsl:apply-templates />
      </A>
    </xsl:template>

    <xsl:template match="B">
      <B>
        <xsl:apply-templates />
      </B>
    </xsl:template>

    <xsl:template match="ADDRESSES">
      <ADDRESSES>
        <xsl:apply-templates />
      </ADDRESSES>
    </xsl:template>

    <xsl:template match="ADDRESS">
        <xsl:variable name="this-id" select="@id" />
        <xsl:choose>
          <xsl:when test="/root/c/addresslists/SBSaddress_[(_at_)id = 
$this-id]">
            <ADDRESS>
              <xsl:copy-of select="/root/c/addresslists/SBSaddress_[(_at_)id =
$this-id]/*" />
            </ADDRESS>
          </xsl:when>
          <xsl:otherwise><xsl:copy-of select="." /></xsl:otherwise>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>
-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Kota, Ganesh <gkota(_at_)GAIC(_dot_)COM>
Sent:     Thu, 2 Nov 2006 10:19:02 -0500
To:       <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject:  [xsl] Help needed to transform in  data joining

Hi, 
I have this XML file , need to do union of all Address and SBSaddress_
elements based on id attribute join condition in XSL file .Address
element has to be overridden in the output if SBSaddress has the data.
I appreciate if anybody can help and give some references on this.
Thanks,
Kota

Input XML file:

<root>
<A>
<B>
<ADDRESSES>
<ADDRESS
id='1'><State>CO</State><Address1/><Address2/><City>flroen</City><Countr
y>UnitedStates</Country><Province>--Select--</Province><ZipCode>11</ZipC
ode><County/></ADDRESS>
<ADDRESS
id='2'><State>KY</State><Address1>campbellcounty</Address1><Address2/><C
ity>fortthomas</City><Country>UnitedStates</Country><Province>--Select--
</Province><ZipCode>41075</ZipCode><County/></ADDRESS>
</ADDRESSES>
</B>
</A>
<c>
<addresslists>
<SBSaddress_
id='1'><State>CO</State><Address1>florence</Address1><Address2/><City>fl
roen</City><Country>UnitedStates</Country><Province>--Select--</Province
<ZipCode>11</ZipCode><County/></SBSaddress_>
<SBSaddress_
id='2'><State></State><Address1></Address1><Address2>bananacounty</<Addr
ess2><City>fortthomas</City><Country>UnitedStates</Country><Province>--S
elect--</Province><ZipCode>11</ZipCode><County/></SBSaddress_>
</addresslists>
</c>
</root>

****************************************************************************
********
The content of this e-mail message and any attachments are confidential
and may be legally privileged, intended solely for the addressee. If you
are not the intended recipient, be advised that any use, dissemination,
distribution, or copying of this e-mail is strictly prohibited.  If you
receive this message in error, please notify the sender immediately by
reply email and destroy the message and its attachments.
****************************************************************************
********

--~------------------------------------------------------------------
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>
--~--




--~------------------------------------------------------------------
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>
--~--




--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>