Altova Mailing List Archives


Re: [xsl] Transforming XML Blockquotes - Mixed Content

From: James Fuller <jim.fuller@-------------->
To:
Date: 4/13/2005 7:47:00 PM
Edward Bryant wrote:

>
> Sorry, I am still a little new to this and I had some trouble
> understanding this response to my post.
>
>> your best bet is to remove all <p/>'s and then apply text() matching
>> template that wraps text with <p/>, along with a blockquote template
>> that just copies itself.
>
>
> If I understand this correctly, the text between two block quotes
> would be treated the same as a simple plain paragraph. I don't think,
> however, this will work because I would lose the attributes of the xml
> tagged paragraphs. My source xml contains paragraphs that contain a
> number attribute, as well as other inline tagging for italics,
> footnotes, etc.
>
> For example:
>
> <paragraph num="1">Yadda Yadda Yadda <italic>Italic Yadda</italic> Yadda:
> <blockquote>Blah Blah Blah Blah</blockquote>
> Yackity Yack Yack</paragraph>
>
ok apply the following to your above xml

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
   
    <xsl:output method="html" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/">
       
        <!-- Transform  -->
        <xsl:variable name="result">
            <xsl:apply-templates select="paragraph"/>
        </xsl:variable>
 
        <!-- Display Results -->
        <xsl:copy-of select="$result"/>
       
    </xsl:template>
   
  <xsl:template match="text()">
        <xsl:if test="normalize-space()">
            <p><xsl:value-of select="normalize-space(.)"/></p>
        </xsl:if>
    </xsl:template>
   
    <xsl:template match="paragraph">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="italic">
        <i>
            <xsl:value-of select="."/>
        </i>
    </xsl:template> 
   
    <xsl:template match="blockquote">
            <xsl:copy-of select="."/>
    </xsl:template>   
   
</xsl:stylesheet>

some assumptions;

xsl:output method could = xhtml
i matched your italic element and replaced with <i>...I used
xsl:value-of to select on the text..u may want to use xsl:copy-of to
select elements

hth, Jim Fuller

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.