Click to See Complete Forum and Search --> : New to XML


rolsen
July 24th, 2001, 12:00 AM
I've just begun to work with XML and so far not to bad, I've been able from a xml document to create output to html, now that was fairly easy so here's the hard part, and question.

How can I format the output, mainly I want to create links in html with xml strings. I can write out the xml strings just fine, but am having great problems trying to format a anchor for a link. Any help would be appreciated.

thanks,
Rick

tyris
July 25th, 2001, 06:04 AM
there is many way to create a link with xml data
here is an example :
<a href="{@url}" >
<xsl:value-of select="description_of_the_link"/>
</a>


it depends on which namespace you use.
the exemple i gave you is for the new namespace, that everyone should use (the old one is pretty useless).

the namepsace is the first line of your xsl : <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

hope this helped

regards

Elise, XML learning girl :-)

rolsen
July 25th, 2001, 09:55 AM
Thanks Elise,

This helped, but now the next problem. What I have is a DOM document that has a CDATA section in it with the http:// reference somewhere in the body of the CDATA. Is there a way in the XSL stylesheet to search for a text pattern, like searching for the http:// and then to use that text to create a <xsl:variable name="url"> that could then be used in the link..<a href="{$url)" >.

Rick

tyris
July 25th, 2001, 10:22 AM
well so you use data island if i've well understood ?
the best would be that you post here the sample code, so i would understand better your problem



regards

Elise, XML learning girl :-)

rolsen
July 25th, 2001, 11:10 AM
Well, I'm not sure what data island's are???, but here's the code.

The XLS file:
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="templates/params/pData">
<xsl:variable name="url"><xsl:value-of select="."/></xsl:variable>
<pre><a href="{$url}" >
<xsl:value-of select="."/></a>
</pre>
</xsl:for-each>
</body>
</html>
</xsl:template>

Now for the XML file:

<templates file="TempHtml.xml" version="1.0">TempHtml
<params>
<name>link</name>
<pData>
<![CDATA[/* this is a test */
http://www.virtual-co.com]]>
</pData>
</params>
</templates>


The CDATA section in the xml file is used to hold code template, this could be any portion of sample code fuctions along with a html link to say a help reference or a website for additional help information. Currently with the above code in the xsl, all of the CDATA shows up in the link. What I would like to do is to parse out just the http:// text and use that for the link.

Is this possible?????

thanks,
Rick

tyris
July 26th, 2001, 08:57 AM
so if i've well understood, in a data that is "http://test.html" you just want to get "http://" and not the rest ?? well, i never tryed to do this... don't even see what i could do of this...

regards

Elise, XML learning girl :-)

rolsen
July 26th, 2001, 09:26 AM
Elise,

In the CDATA section there could lots of text, and then somewhere imbedded in that text there might be a link. I want the whole link, whatever that might be, it could be http://www.new.com, it could be a file://c:/thisdirectory/thisfile.html.

I was hoping there was some type of pattern seach that could be used to search thru the text to find the link. Is that possible????

Rick

tyris
July 26th, 2001, 11:04 AM
well i don't think so... how could you define the end of the url ? it can end with .com, .net, .fr ... and so on.
i have sometime used small javascript functions to get only a part of a string... i've seen it also in vbscript, but those functions are very specific and quite big to code... maybe you could do this in javascript, and use XML DOM to read xml data with javascript...
the best would be to use a specific tag for the url, this way :

<description>blzahhhhfdfe</description>
<url>www.test.com/verify.html<url>

regards

Elise, XML learning girl :-)

rolsen
July 26th, 2001, 11:16 AM
Elise, you been very helpful, thanks.

I think I maybe have confused things though, the url is complete in the CDATA section of the XML file, if I had separated this out into its own element I wouldn't have this problem. But the complete link is mixed amongst other text, what this might look like is say an technical article with reference links to other technical articles.

So what I was looking to do was to somehow parse the CDATA to get the links. I don't know whats available in XML to do pattern searchs, or even if there is such a function.

thanks,
Rick