RE: [xsl] XML content check against the ms-excel content

Subject: RE: [xsl] XML content check against the ms-excel content
From: "Selvaganesh" <selvaganesh_t@xxxxxxxxxxxxxx>
Date: Sat, 28 Nov 2009 13:07:06 +0530
Hi Ken,

Thank you for the help.

Thanks lot,
Selva

-----Original Message-----
From: G. Ken Holman [mailto:gkholman@xxxxxxxxxxxxxxxxxxxx] 
Sent: Saturday, November 28, 2009 12:54 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] XML content check against the ms-excel content

At 2009-11-28 12:21 +0530, Selvaganesh wrote:
>Here listed my details,

Thank you for being explicit.  This made answering easy.

>This is my input XML file:
>...
>This is my input Excel XML file:
>...
>I expect the output:
>
><b><span style="background-color: Green">mulberrytech</span></b>
><b><span style="background-color: Red">xsltech1</span></b>
>
>How to write the xslt coding.

You don't say if you needed the answer in XSLT 2 or XSLT 1, so both 
answers are below.

Note that because the processor will cache the referenced document, 
there is no performance penalty using the document() function repeatedly.

The answer involves using a key for a lookup table and looking inside 
the Excel file while reading the input file.

I hope this helps.

. . . . . . . . .  Ken

t:\ftemp>type reference.xml
<root>
     <reference>
         <id>ID001</id>
         <title>mulberrytech</title>
     </reference>
     <reference>
         <id>ID002</id>
         <title>xsltech1</title>
     </reference>
</root>

t:\ftemp>type selva.xml
<root>
     <p>
         <reference id="ID001">mulberrytech</reference>
     </p>
     <p>
         <reference id="ID001">xsltech1</reference>
     </p>
</root>

t:\ftemp>call xslt2 selva.xml selva.xsl
<?xml version="1.0" encoding="UTF-8"?>
<b>
    <span style="background-color: Green">mulberrytech</span>
</b>
<b>
    <span style="background-color: Red">xsltech1</span>
</b>
t:\ftemp>type selva.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                 version="2.0">

<xsl:output indent="yes"/>

<xsl:key name="ref" match="reference" use="title"/>

<xsl:template match="/">
   <xsl:for-each select="*/p">
     <b>
       <span style="background-color: {
                    if( key('ref',reference,doc('reference.xml'))/id =
                        reference/@id )
                    then 'Green' else 'Red'
                    }">
         <xsl:value-of select="reference"/>
       </span>
     </b>
   </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

t:\ftemp>call xslt selva.xml selva1.xsl
<?xml version="1.0" encoding="utf-8"?>
<b>
    <span style="background-color: Green">mulberrytech</span>
</b>
<b>
    <span style="background-color: Red">xsltech1</span>
</b>
t:\ftemp>type selva1.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                 version="1.0">

<xsl:output indent="yes"/>

<xsl:key name="ref" match="reference" use="title"/>

<xsl:template match="/">
   <xsl:for-each select="*/p">
     <b>
       <span>
         <xsl:attribute name="style">
           <xsl:text>background-color: </xsl:text>
           <xsl:variable name="given" select="reference"/>
           <xsl:for-each select="document('reference.xml')">
             <xsl:choose>
               <xsl:when 
test="key('ref',$given)/id=$given/@id">Green</xsl:when>
               <xsl:otherwise>Red</xsl:otherwise>
             </xsl:choose>
           </xsl:for-each>
         </xsl:attribute>
         <xsl:value-of select="reference"/>
       </span>
     </b>
   </xsl:for-each>
</xsl:template>

</xsl:stylesheet>



--
Vote for your XML training:   http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal



Confidentiality Notice:  This transmittal is a confidential communication.  If you are not the intended recipient, you are hereby notified that you have received this transmittal in error and that any review, dissemination, distribution or copying of this transmittal is strictly prohibited.  If you have received this communication in error, please notify this office immediately by reply and immediately delete this message and all of its attachments, if any.

Current Thread