[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Search and Replace in XSLT
Ciaran, >let's say I have: > ><img src="x.bmp" alt="[tag]"/> > >and I want to replace '[' with '<' to get the output > ><img src="x.bmp"> ><tag/> > >using Michaels' technique I get the usual entity problem in XML >i.e. the output becomes: > ><img src="x.bmp"> ><tag/< > >which is no good to me as I need the proper tag. You're thinking about generating XML in the wrong way if you want to use XSLT to do it. Rather than thinking "I am generating a string, with a '<', then the string 'tag', then a '/', then a '>', to give an empty element called 'tag'", you should be thinking "I am generating an empty element called 'tag'". [This goes for other things as well as just generating elements: XSLT processes and produces a *structure*, not a sequence of characters.] To generate an element with a variable name (presumably the @alt attribute could hold anything), you can use the xsl:element element: <xsl:element name="..."> ... </xsl:element> [For an empty element, <xsl:element name="..." />] The value of the @name attribute on xsl:element should be an XPath that selects something with a string value that gives you the name. Let's say you're matching on the 'img' element: <xsl:template match="img"> ... </xsl:template> Within this template, the current node is the 'img' element, so you can get the value of the @alt attribute through the XPath '@alt': <xsl:template match="img"> ... <xsl:element name="@alt" /> </xsl:template> In your case, this would actually give you an element called '[tag]', which isn't a valid name for an element, so you need to do a bit of string-munging to get rid of the '[' and ']' first: <xsl:template match="img"> ... <xsl:element name="string-after(string-before(@alt, ']'), '[')" /> </xsl:template> I hope that this helps, Jeni Dr Jeni Tennison Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE Telephone 0115 9061301 ? Fax 0115 9061304 ? Email jeni.tennison@xxxxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|