I’m having difficulty conceptualizing how to go about converting an image’s relative path to an absolute path via xslt.
There currently exists an XML document that has a section <myHTML> which holds html encoded text. This html document may contain <img> tags with relative paths – For example: <img src="myPic.jpg>
There also exists a xsl that processes that section with a block like this:
<div id="bodyText">
<xsl:value-of select="/abc:myT/abc:myHTML" disable-output-escaping="yes">
</div>
I need to prepend an absolute path to the beginning of the image name. Since the whole html block is being accessed via value-of select, I’m not sure how to attack this.
I do believe that I need to use an xsl input parameter in order to pass in the path, but not sure how to access the <img> tag inside <myHTML>.
And advice would be appreciated.
Update
There were some questions as to the format of the XML file and what I meant by “html encoded text”. Please disregard typos, the below chunk is from memory and is representative of the actual xml file. It is meant to illustrate the HtmlEncode() data in the <myHTML> block.
<?xml version="1.0" encoding="UTF-8">
<?xml-stylesheet ...snipped..>
<myT xmlns="abc">
<myHTML>
<html$gt;<head$gt;<title$gt;This is my title</title$gt;</head$gt;
<body$gt;
<img src="myPic.jpg" /$gt;
</body$gt;</html$gt;
</myHTML>
</myT>
Additionally, as Dimitre pointed out, i’m using .NET and it’s XSLT 1.0 processor.
Unless there is a good reason forcing you to use XLST for this, I’d suggest that it’s the wrong tool for the job. Load the XML document into a DOM and XPath to get a node-set containing the relevant myHtml elements. Unescape the HTML and load it into an HTML parser (or if it’s XHTML, an XML parser).. again XPath to get the img element, and read/write the href attributes.
In any case – it might help if you could update the question with more details of your problem. Are there constraints forcing you to use XSLT? (In which case, is the HTML escaped in a way that you could reliably regex against?) Is performance an issue? What sort of application is it? Etc. Etc.