xsl-list
[Top] [All Lists]

Re: [xsl] Compare 2 XML and call id in main xml in sucess is true

2016-09-22 04:03:10
On 21/09/16 20:23, Rahul Singh rahulsinghindia15(_at_)gmail(_dot_)com wrote:
Hi,

I have 2 XML. result.XML and name.xml. I am comparing both XML and
calling with corresponding XML from result.xml to name.xml if
sucess=true case. And if sucess =false case , i need corresponding XML
chunk from name.xml.

You don't say what the condition for a match is. If you are just
comparing result[position()] to Name[position()] then I don't see where
there is a need for a true/false test.

///Peter

*result.xml:*

<?xml version="1.0" encoding="UTF-8"?>
<results>
   <result>
        <id>001R0000018j3KBIAY</id>
        <success>true</success>
     </result>
   <result>
        <id>001R0000018j3KCIAY</id>
        <success>true</success>
     </result>
   <result>
        <id>001R0000018j3KDIAY</id>
        <success>true</success>
     </result>
   <result>
        <id>001R0000018j3KEIAY</id>
        <success>true</success>
     </result>
   <result>
        <id xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
<http://www.w3.org/2001/XMLSchema-instance>" xsi:nil="true"/>
        <success>false</success>
     </result>
    <result>
        <id>001R0000018j3KFIAY</id>
        <success>true</success>
     </result>
</results>

*Name.xml:*


<Names>
   <Name>
      <LAST_NAME>rtt</LAST_NAME>
      <FIRST_NAME>ds</FIRST_NAME>
   </Name>
   <Name>
      <LAST_NAME>jhj</LAST_NAME>
      <FIRST_NAME>tyt</FIRST_NAME>
   </Name>
   <Name>
      <LAST_NAME>qwqw</LAST_NAME>
      <FIRST_NAME>i</FIRST_NAME>
   </Name>
   <Name>
      <LAST_NAME>trt</LAST_NAME>
      <FIRST_NAME>ss</FIRST_NAME>
   </Name>
   <Name>
      <LAST_NAME>yt</LAST_NAME>
      <FIRST_NAME>asa</FIRST_NAME>
   </Name>
</Names>


*XSLT: *

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform
<http://www.w3.org/1999/XSL/Transform>">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>
    <xsl:strip-space elements="*"/>
    <xsl:param name="tranFile" select="document('Name.xml')"/>

    <xsl:template mode="insert" match="Names">
        <xsl:copy-of select="../../Name"/>
    </xsl:template>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:apply-templates mode="insert" select="."/>
            <xsl:apply-templates mode="inserta" select="."/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

    <xsl:template mode="insert" match="*"/>
    <xsl:template mode="inserta" match="*"/>


    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>


*Expected Output:*


<Names>
   <Name>
      <LAST_NAME>rtt</LAST_NAME>
      <FIRST_NAME>ds</FIRST_NAME>
  <id>001R0000018j3KBIAY</id>
   </Name>
....
....

</Names>


XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/643318>
(by email <>)


///Peter
-- 
Peter Flynn | Academic & Collaborative Technologies | University College
Cork IT Services | ☎ +353 21 490 2609 | ✉ pflynn(_at_)ucc(_dot_)ie | 🌍 
www.ucc.ie
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

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