xslt

.Net XML comment into API Documentation

Is there an easy way to produce MSDN-style documentation from the Visual Studio XML output? I'm not patient enough to set up a good xslt for it because I know I'm not the first person to cross this bridge. Also, I tried setting up sandcastle recently, but it really made my eyes cross. Either I was missing something important in the pr...

How do you use a variable in xsl when trying to select a node?

I would have thought this would be an easy one to Google, but I've been unsucessful. I want to assign a variable the value out of an attribute (easy so far) then use that variable to select another node based on the value of that attribute. ex: <xsl:variable name="myId" select="@id" /><xsl value-of select="//Root/Some/Other/Path/Where...

Is it "bad practice" to be sensitive to linebreaks in XML documents?

I'm generating some XML documents and when it comes to the address part I have fragments that look like this: <Address>15 Sample St Example Bay Some Country</Address> The XSLT that I have for converting this to XHTML has some funky recursive template to convert newline characters within strings to <br/> tags. This is all working fine...

VS2008 SP1 crashes when debugging an XSLT file

I'm using VS2008 SP1 - don't know if this would have happened before I applied SP1 as I never tried it before yesterday. I attempted to debug a fairly simple XSLT file using VS2008 SP1 and got this crash from VS2008 SP1: Microsoft Visual Studio Unexpected error encountered. It is recommended that you restart the application as soon a...

XSLT - Reverse Find in a string

I need to be able to find the last occurrance of a character within an element. for example: <mediaurl><http://www.blah.com/path/to/file/media.jpg&gt;&lt;/mediaurl&gt; If I try to locate through using substring-before(mediaurl, '.') and substring-after(mediaurl, '.') then it will, of course, match on the first dot. How would I get t...

XSL Dynamic Element Names

I want to transform an XML document. The source XML looks like this: <svc:ElementList> <svc:Element> <Year>2007</Year> </svc:Element> <svc:Element> <Year>2006</Year> </svc:Element> <svc:Element> <Year>2005</Year> </svc:Element> </svc:ElementList> I want to turn that into: <ElementList> ...

XSLT Find and Replace with Unique

I am performing a find and replace on the line feed character (&#10;) and replacing it with the paragraph close and paragraph open tags using the following code: <xsl:template match="/STORIES/STORY"> <component> <xsl:if test="boolean(ARTICLEBODY)"> <p> <xsl:call-template name="replace-text"> <xsl:with-p...

using a html entity in xslt (e.g. &nbsp;)

what is the best way to include a htlm entity in XSLT? <xsl:template match="/a/node"> <xsl:value-of select="."/> <xsl:text>&nbsp;</xsl:text> </xsl:template> this one returns a XsltParseError ...

XSLT nodesets Length

In XLST how woud you find out the length of an nodesets? ...

XSLT dividing a list of nodes in half

<xsl:for-each select="./node [position() &lt;= (count(*) div 2)]"> <li>foo</li> </xsl:for-each> <xsl:for-each select="./node [count(*) div 2 &lt; position()]"> <li>bar</li> </xsl:for-each> My list has 12 nodes, but the second list is always 8 and the first is always 4. What's wrong with my selects? ...

How to apply an XSLT Stylesheet in C#

I want to apply an XSLT Stylesheet to an XML Document using C# and write the output to a File. Edit: @Rob Cooper: Yes, I am aware of that. But I couldn't find it in SO. The Idea of this site is to collect answers to any question a developer could have, right? I had this question today and thus posted an answer. Next time I look (this i...

ASP.NET MVC vs. XSL

Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of data on a web-page with XSL over ASP.NET MVC? The two alternatives are: ASP.NET (MVC/WebForms) with XSL Getting the data from the database and transforming it to XML which is then displayed on the different pages with XSL-templates. ASP.NET MVC Ge...

Can I create a value for a missing tag in XPath?

I have an application which extracts data from an XML file using XPath. If a node in that XML source file is missing I want to return the value "N/A" (much like the Oracle NVL function). The trick is that the application doesn't support XSLT; I'd like to do this using XPath and XPath alone. Is that possible? ...

How to Convert a StreamReader into an XMLReader object in .Net 2.0/C#

Here's a quick question I've been banging my head against today. I'm trying to convert a .Net dataset into an XML stream, transform it with an xsl file in memory, then output the result to a new XML file. Here's the current solution: string transformXML = @"pathToXslDocument"; XmlDocument originalXml = new XmlDocumen...

If you were programming a calendar in HTML would you use Table tags or Div tags?

I converted my company's calendar to XSL and changed all the tables to divs. It worked pretty well, but I had a lot of 8 day week bugs to work out initially owing to precarious cross-browser spacing issues . but I was reading another post regarding when to use tables v. divs and the consensus seemed to be that you should only use divs fo...

How do you add an image in XSLT?

I have a simple XML document that contains image information. I need to transform it to HTML -- simple, right? However, when I use the XSL below, it blows up with the error "Cannot write an attribute node when no element start tag is open." I can't see where the open tag is -- any ideas? XML: <root> <HeaderText> <HeaderTex...

xslt: apply-templates in reverse order

say i have this given xml file <root> <node>x</node> <node>y</node> <node>a</node> </root> and i want the following to be displayed ayx using something similar to <xsl:template match="/"> <xsl:apply-templates select="root/node"/> </xsl:template> <xsl:template match="node"> <xsl:value-of select="."/> </xsl:templ...

What is a good resource for learning XSL?

Recently, I have started to have to read a lot of XSL and XSLT at my job. Some of it makes sense and some of it really doesn't. Here's an exmaple of what does not make sense to me <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; <xsl:output method="html" encoding="UTF-8" /> ...

How to validate an XML file against a schema using Visual Studio 2005

Is it possible to validate an xml file against it's associated schema using Visual Studio 2005 IDE? I could only see options to create a schema based on the current file, or show the XSLT output ...

How can I lay images out in a grid using XSL-FO?

I'm trying to produce sheets of photographs with captions arranged in a grid using XSLT and XSL-FO. The photo URLs and captions are produced using a FOR XML query against an SQL Server database, and the number of photos returned varies from sheet to sheet. I want to lay the photos out in four columns, filling the grid from left to right ...