Link to home
Start Free TrialLog in
Avatar of jas_tvpm
jas_tvpm

asked on

referencing sites in xsl using xml

hi,
i am a beginner in xml. i hav two files one xml and other xsl as given below.
my aim is to get particular sites by clicking the reference.
how can i do that,
first time i got the links displayed, but now nothing is coming.
can u modify this programs or give me guidelines.
thanks
jasmine

websites.xml

<?xml version="1.0"?>
<?xml-stylesheet href="WebSites.xsl"
                 type="text/xsl"?>
<WebSites>
     <Tourism>
           <Name>Expedia</Name>
           <Name>kcts</Name>    
           <Name>indtravel</Name>
           <Name>travelanza</Name>  
     </Tourism>
     <Automotive>
           <Name>carsdirect</Name>
           <Name>carsmart</Name>
           <Name>motortrend</Name>
           <Name>autotrader</Name>
     </Automotive>    
     <Movies>
           <Name>boxofficereport</Name>
           <Name>movies</Name>
           <Name>imdb</Name>
           <Name>mgm</Name>
     </Movies>
     <Jobs>
           <Name>job</Name>
           <Name>govtjobs</Name>
           <Name>hotjobs</Name>
           <Name>recruitersonline</Name>
     </Jobs>
</WebSites>

websites.xsl

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:template match="/">
          <xsl:apply-templates select="WebSites"/>
             </xsl:template>

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

     <xsl:template match="Name">
          <a name="link" href="{concat('http://www.',Name,'.Com')}" target="Mywindow">
          <xsl:value-of select=". "/></a><BR/>
 
     </xsl:template>
 </xsl:stylesheet>
Avatar of xyzzer
xyzzer

Instead of just putting "<a name ...." I do it like this:

<xsl:element name="a">
  <xsl:attribute name="href">
    <xsl:value-of select="tagofurl"/>
  </xsl:attribute>
  <xsl:attribute name="class">
    classnameforcss
  </xsl:attribute>
  <xsl:value-of select="tagoftexttodisplay"/><br/>
</xsl:element>

I guess You could also put Your:
  {concat('http://www.',Name,'.Com')}
or some modification of this instead of:
  "<xsl:value-of select="tagofurl"/>"
Maybe:
  http://www.<xsl:value-of select="Name"/>.com
would work, but as a beginner in xml I'm not sure too
PS there should be something like:
_http://www.<xsl:value-of select="Name"/&gt;.com
in the last line of my prev. comment...

--Filip
Still no good, though You should have no problems deciphering it - I will try again just to lear how to do that in the future:
http:// www.&lt;xsl:value-of select="Name"/>.com
http:// www.<xsl:value-of select="Name"/>.com

Sorry for this...
--Filip
 XSL that does work for what you want..
  The problem with yours was once the Website template was applied, it was expecting the XML to look like this
<Websites>
    <Name>foo</Name>
</websites>
    When in acutallity the names were underneath their respective sub headings..


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
         <xsl:apply-templates select="WebSites"/>
            </xsl:template>

    <xsl:template match="WebSites">
         <xsl:apply-templates select="Tourism"/>
      <xsl:apply-templates select="Automotive"/>
      <xsl:apply-templates select="Movies"/>
         <xsl:apply-templates select="Jobs"/>  
    </xsl:template>

    <xsl:template match="Tourism">
     <h3>Tourism</h3><br/>
     <xsl:for-each select="Name">
         <a name="link" href="{concat('http://www.',. ,'.Com')}" target="Mywindow">
         <xsl:value-of select=". "/></a><BR/>
      </xsl:for-each>
    </xsl:template>

    <xsl:template match="Automotive">
     <h3>Automotive</h3><br/>
     <xsl:for-each select="Name">
         <a name="link" href="{concat('http://www.',. ,'.Com')}" target="Mywindow">
         <xsl:value-of select=". "/></a><BR/>
      </xsl:for-each>
    </xsl:template>

    <xsl:template match="Movies">
     <h3>Movies</h3><br/>
     <xsl:for-each select="Name">
         <a name="link" href="{concat('http://www.',. ,'.Com')}" target="Mywindow">
         <xsl:value-of select=". "/></a><BR/>
      </xsl:for-each>
    </xsl:template>

    <xsl:template match="Jobs">
     <h3>Jobs</h3><br/>
     <xsl:for-each select="Name">
         <a name="link" href="{concat('http://www.',. ,'.Com')}" target="Mywindow">
         <xsl:value-of select=". "/></a><BR/>
      </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
ASKER CERTIFIED SOLUTION
Avatar of ksokolowski
ksokolowski

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jas_tvpm

ASKER

Hi sir Thanks for the pgm.the modifications u made works better
 Please accept my comment as an answer if I have been of help to you!  Thanks!!
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept ksokolowski's comment
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

FaithRaven
EE Cleanup Volunteer