Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

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>
0
jas_tvpm
Asked:
jas_tvpm
1 Solution
 
xyzzerCommented:
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
0
 
xyzzerCommented:
PS there should be something like:
_http://www.<xsl:value-of select="Name"/&gt;.com
in the last line of my prev. comment...

--Filip
0
 
xyzzerCommented:
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
ksokolowskiCommented:
 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>
0
 
ksokolowskiCommented:
Here is a better way to my above way.. This is more similar to your original one..

<?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/Name"/>
      <xsl:apply-templates select="Automotive/Name"/>
      <xsl:apply-templates select="Movies/Name"/>
      <xsl:apply-templates select="Jobs/Name"/>
     </xsl:template>


    <xsl:template match="Name">
         <a name="link" href="{concat('http://www.',.,'.Com')}" target="Mywindow">
         <xsl:value-of select=". "/></a><BR/>
 
    </xsl:template>
</xsl:stylesheet>
0
 
jas_tvpmAuthor Commented:
Hi sir Thanks for the pgm.the modifications u made works better
0
 
ksokolowskiCommented:
 Please accept my comment as an answer if I have been of help to you!  Thanks!!
0
 
FaithRavenCommented:
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now