xsl-list
[Top] [All Lists]

RE: [xsl] Evaluating XML inside attributes (using XSLT 2.0 and Saxon)

2010-03-24 17:41:20
We more usually see this problem in the form of escaped markup inside CDATA
sections, but essentially it's the same problem and the same solution (and
the same note of censure that whoever designed this XML should be shot at
dawn). Because the markup has been escaped, it escapes the attention of the
XML parser the first time through. You have to extract the attribute value
as a string, and then pass it to an XML parser for re-parsing. You can't do
that in standard XSLT, but you can do it by calling the saxon:parse()
extension function. You'll have to wrap it in an element to make it
well-formed: so you will want something like

saxon:parse(concat("<wrapper>", @title, "</wrapper>" ))

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

-----Original Message-----
From: Jacobus Reyneke [mailto:jacobusreyneke(_at_)gmail(_dot_)com] 
Sent: 24 March 2010 18:39
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Evaluating XML inside attributes (using XSLT 
2.0 and Saxon)

Good day,

This is in relation to my earlier posts, but I have not yet 
been able to solve my problem. I have tried working around 
the problem below, but because of the type of information I'm 
working with (labeling and vector graphics), I can't get past 
the fact that sometimes I end up with attributes that will 
get part of their content from other parts of the XML document.

Can anyone please share some ideas around evaluating 
information for use inside xml attributes. I know it's ugly, 
horrible and terrible to escape XML an dump it inside an 
attribute, but I need to reference content by id from inside 
attributes from time to time. I can move attributes out into 
child elements, but this can become even more confusing.

Input:
<root>
  <name lookup-id="5">
    Johny
  </information>
  <chapter title="The life of &lt;x&gt;5&lt;/x&gt;">
     Everyone knew that <x>5</x> was a happy child
  </chapter>
</root>

XSLT
???

Required output:
<root>
  <name lookup-id="5">Johny</information>
  <chapter title="The life of Johny">Everyone knew that Johny 
was a happy child</chapter> </root>

I'm unable to get the XSLT processor to evaluate the content 
of the title attribute. Obviously a template matching x does 
not get called for content inside attributes.

A generic approach would be ideal. Something that will work 
no matter where <x>5</x> is.

Kind regards,
Jacobus

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--