Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / April 2006

Tip: Looking for answers? Try searching our database.

XSLT: Creating anchors from outer XML files

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mario Vázquez - 24 Apr 2006 21:29 GMT
Hi,
I'm trying to put the links (href attribute of the <a> element) out of my
XSLT files, in a XML file, and read it from the stylesheet. I suppose that I
have to use the document() function to link to the XML file containing the
URLs, but I don't know how to do it. I've tried something like this:

This is XML file containing the URLs (link.xml):

<?xml version="1.0" encoding="utf-8" ?>
<LINKS>
<L1>
 /SomePage.aspx
</L1>
</LINKS>

And this is the code from the stylesheet:

<a href="{document('link.xml')/LINKS/L1}" >
   Some text for the anchor
</a>

But does not work. I've tried to move the XML file in different folders to
make the things easy... but with no luck.

How this it's supposed to be done?

Thanks for any suggest.
Mario Vazquez
Oleg Tkachenko [MVP] - 25 Apr 2006 10:35 GMT
> I'm trying to put the links (href attribute of the <a> element) out of my
> XSLT files, in a XML file, and read it from the stylesheet. I suppose that I
[quoted text clipped - 18 lines]
> But does not work. I've tried to move the XML file in different folders to
> make the things easy... but with no luck.

Should work. Make sure that link.xml is stored in the same directory as
your stylesheet. Also you may want to remove whitespace before and after
link text:

<a href="{normalize-space(document('link.xml')/LINKS/L1)}" >

Another idea - in .NET 2.0 when using XslCompiledTransform class
document() function is disabled by default - you should get an exception
though.

Signature

Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com

George Bina - 25 Apr 2006 11:02 GMT
Hi Mario,

That should work. Note that in this case link.xml in resolved relative
to the stylesheet location. If you want it to be resolved relative to
the XML file location then use

<a href="{document('link.xml', .)/LINKS/L1}" >
   Some text for the anchor
</a>

That is you need to pass a node set as a second argument to the
document funtion and that nodeset system Id will be used to resolve the
relative location specified as the first argument.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Mario Vázquez - 25 Apr 2006 14:28 GMT
Thanks for repply!
Is ther any way to reffer to the base root of a web application?
Something like the ~ character in server side.

thanks in advance

> Hi Mario,
>
[quoted text clipped - 16 lines]
> <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
> http://www.oxygenxml.com
Martin Honnen - 25 Apr 2006 14:50 GMT
> Is ther any way to reffer to the base root of a web application?
> Something like the ~ character in server side.

You can declare a parameter e.g.
  <xsl:param name="dir" />
in your stylesheet and then pass in a value as needed before you run the
transformation. That way you could for instance use Server.MapPath() in
ASP to determine a file path and pass that then in to the XSLT processor.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.