Google Groups Home
Help | Sign in
Stupid XML and xslt question
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Eoj  
View profile
 More options Nov 21 2008, 4:14 am
From: Eoj <josephmeir...@gmail.com>
Date: Thu, 20 Nov 2008 09:14:21 -0800 (PST)
Local: Fri, Nov 21 2008 4:14 am
Subject: Stupid XML and xslt question
Hello, new to xml markup, have a question. Need to display a hyperlink
in a marked up xml file, here is an excerpt. . .
=========================================================================== =====
<NewDataSet>

      <Table>
        <pic>&lt;a href=http://cas.sdss.org/dr7/en/tools/chart/
navi.asp?ra=166.358&amp;dec=-0.748596&gt;
                &lt;img src="http://casjobs.sdss.org/ImgCutoutDR7/getjpeg.aspx?
ra=166.358&amp;dec=-0.748596&amp;scale=0.40&amp;width=120&amp;height=120&am p;opt="/
&gt; </pic>

        <name>J1105<name>

        <ra>16.25829</ra>

        <dec>-7.74849605</dec>

        <mag_g>18.9</mag_g>

        <id>587722982270959696</id>

        <sep>0.02</sep>

 /Table>

</NewDataSet>
=======================================================

and the xsl is below. The table as displayed in html only has the long
link that is not clickable. How does one make a clickable hyperlink
from an xml database?

==================================================

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/


<xsl:template match="/">
  <html>
  <body>
  <h2>Lots of Junk</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th align="left">pic</th>
        <th align="left">name</th>
     </tr>
      <xsl:for-each select="NewDataSet/Table">
      <tr>
        <td><xsl:value-of select="pic"/></td>
        <td><xsl:value-of select="name"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Cerebrus  
View profile
 More options Nov 21 2008, 6:36 am
From: Cerebrus <zorg...@sify.com>
Date: Thu, 20 Nov 2008 11:36:30 -0800 (PST)
Local: Fri, Nov 21 2008 6:36 am
Subject: Re: Stupid XML and xslt question
1. Your XML isn't well formed.
2. To accurately decode escaped HTML, you would need an extension
function or you could do it using a template that searches for and
replaces all occurrences of the required entities.
2. Instead of trying to include HTML within XML, I would rather let it
contain what it is designed for - storage of data. To elaborate, my
XML would rather be :

---
<?xml version="1.0"?>
<NewDataSet>
  <Table>
    <link>http://cas.sdss.org/dr7/en/tools/chart/navi.asp?
ra=166.358&amp;dec=-0.748596</link>
 <img>http://casjobs.sdss.org/ImgCutoutDR7/getjpeg.aspx?
ra=166.358&amp;dec=-0.748596&amp;scale=0.40&amp;width=120&amp;height=120&am p;opt=</
img>
    <name>J1105</name>
    <ra>16.25829</ra>
    <dec>-7.74849605</dec>
    <mag_g>18.9</mag_g>
    <id>587722982270959696</id>
    <sep>0.02</sep>
  </Table>
</NewDataSet>
---

And I would use the following XSLT to get an accurate result :

---
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/


<xsl:template match="/">
  <html>
  <body>
  <h2>Lots of Junk</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th align="left">pic</th>
        <th align="left">name</th>
     </tr>
      <xsl:for-each select="NewDataSet/Table">
      <tr>
        <td>
          <xsl:element name="a">
            <xsl:attribute name="href">
              <xsl:value-of select="link" />
            </xsl:attribute>
            <xsl:element name="img">
              <xsl:attribute name="src">
                <xsl:value-of select="img" />
              </xsl:attribute>
            </xsl:element>
          </xsl:element>
        </td>
        <td><xsl:value-of select="name" /></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
---

This way, I do not need to bother about escaping HTML tags because
they are not present in the XML. The XML only stores the data which
will become the attributes of a tag.

On Nov 20, 10:14 pm, Eoj <josephmeir...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eoj  
View profile
 More options Nov 27 2008, 2:42 am
From: Eoj <josephmeir...@gmail.com>
Date: Wed, 26 Nov 2008 07:42:13 -0800 (PST)
Local: Thurs, Nov 27 2008 2:42 am
Subject: Re: Stupid XML and xslt question
Thanks! Well, I don't have control over the xml output, its done as
the output of an sql search. I suppose I could use sed to fix the xml
sheet into something more well behaved. ..

Cheers,
Joe

On Nov 20, 2:36 pm, Cerebrus <zorg...@sify.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google