xsl-list
[Top] [All Lists]

[xsl] inline XML <emphasis>

2008-02-28 20:37:58
There is a little nuance that makes this problem
interesting. I can of course use the built-in template
to preserve the order of  the text nodes. But mainly I
want to split (tokenize?) the "unemphasized" text node
at the root of the <para> element and capture each
fragment separately in an <emphasis type="default">
element while keeping all elements of all emphasis
types in sequence.

I get very close if I add a closing emphasis tag,
</emphasis>, before my literal element and reopen the
<emphasis type="default"> after my
literal element. However, I am serializing back to XML
and doing this raises an objection from the processor.
I tried to fool the processor by using entity
references, but then the entity reference remains in
the
result XML. This is my stylesheet so far:


<xsl:template match="/">
       <xsl:apply-templates/>
</xsl:template>

<xsl:template match="para">
<emphasis type="default">
       <xsl:apply-templates/>
</emphasis>
</xsl:template>

<xsl:template match="emphasis">
&lt;/emphasis&gt;  <---------------HERE
<emphasis>
       <xsl:attribute name="type" select="@*"/>
       <xsl:apply-templates/>
</emphasis>
&lt;emphasis type="default"&gt; <------AND HERE
</xsl:template>

without the hack of adding closing THEN opening
literal snippets, I am pretty much where I started, by
the way.

The goal of this is to use in a variable data text
application that
looks at each tag and switches on the correct font
based on the emphasis type. That's why the text's XML
must end up styled more like HTML with <span> tags
than a hierarchical structure (but only within the
para elements).


UPDATE: It works! The final ingredient can be a
"disable-output-escaping" attribute around the closing
and opening literals and the entities come back as
actual brackets. However, I imagine that this problem,
by its nature, must come up quite often. Is there a
better way of solving it than the hack I suggest?


ORIGINAL POST (and solution):

 I'm working with XML in the following form:

 <cat>
 <para>This is unstyled text <emphasis
type="bold">and
 this is bold. </emphasis>Now back to unstyled
 text.</para>
 </cat>


 As you can see it has some inline style information
 that's borderline not-well-formed. For my ease of
use
 I want the XML in this form (or the equivalent
 result):

 <cat>
 <para><emphasis type="default">This is unstyled
text
 </emphasis><emphasis type="bold">and this is bold.
 </emphasis><emphasis type="default">Now back to
 unstyled text.</emphasis></para>
 </cat>
Just take the identity transformation and add:
<xsl:template match="para/text()">
   <emphasis type="default">
      <xsl:value-of select="."/>
   </emphasis>
</xsl:template>
This way you select only text-nodes which are children
of the para
 element.

As extra credit :~) I want to keep possible nesting
in
mind, although my initial problem is already a sort
of
nesting problem, isn't it?



      
____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>