SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    ********* Genius zweistein's Avatar
    Join Date
    Aug 2001
    Location
    Croatia
    Posts
    290
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow XML and tag elements

    Hello.

    I am trying to use something out of the features XML has to offer, and I came to an interesting problem for which I can't find a solution.

    I have something like this in my code:
    <link path="http://www.google.com">Google websearch</link>

    (just an example).

    I want to transform it with XSL into this:

    <a href="http://www.google.com">Google websearch</a>

    How can I do it? I can't seem to find how to transform tag elements (like "href" in the tag "a") nowhere.

    Thanks for your help!
    zweistein.web - tips&tricks for webmasters, music, programming, computers, Python, etc. new!!! English version, too!
    email | ICQ: 161202879 | AIM: zweistein2169

  2. #2
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only way I know how to do it is to create an attribute node within an <a> node and set the value of the href attribute to the path attribute. There's probably cleaner/better ways so you may want to have a search on xml specific sites.

    (NB: I'm using the MS xml parser V3 sp1)

    Code:
    <!-- Links xml file -->
    <?xml version="1.0"?>
    <?xml:stylesheet type="text/xsl" href="links.xsl" ?>
    <links>
    	<link path="www.google.com">Google</link>
    	<link path="www.yahoo.com">Yahoo</link>
    </links>
    Code:
    <!-- Links xsl file -->
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:template match="/">
    
    	<xsl:for-each select="links/link">
    		<a>
    		<xsl:attribute name="href">
    			<xsl:value-of select="./@path"/>
    		</xsl:attribute>
    		<xsl:value-of select="."/>
    		</a>
    		<br />
    	
    	</xsl:for-each>
    </xsl:template>
    
    </xsl:stylesheet>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •