[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

inline XML <emphasis>

Subject: inline XML <emphasis>
From: Thomas Kielczewski <thomaskiel@xxxxxxxxx>
Date: Thu, 28 Feb 2008 19:37:30 -0800 (PST)
 inline XML <emphasis>
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.