This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: XSL outputting HTML from an XML source
Ariel Garza wrote:
>
> This is close to what I need but the problem I have where this template
> is called. In order for this to process a <B> tag, it would need to be
> called in the same node as the <B> tag exists. I tried to do this:
>
> <xsl:template match="//B">
> <B><xsl:value-of select="B"/></B>
> </xsl:template>
When you are inside this template, you are inside the <B> element.
So <... select="B"> will be referring to children of the current <B>
element that are also <B> elements. What you want is <... select=".">.
But, even better, why not apply templates, which will by default copy
text through, but handle italics inside the <B>. You can handle all of
your formatting tags like this :
<xsl:template match="B|I"> <!-- etc -->
<xsl:copy> <!-- copies the start tag, without attributes -->
<xsl:apply-templates /> <!-- processes children -->
</xsl:copy> <!-- close tag -->
</xsl:template>
> but this doesn't get applied with every template. The root of my
> problem is that I will not necessarily know where any of these tags will
> happen. If the person entering content into the XML wants to have an
> underline or italics inline with other content, they would probably put
> <i>blah blah blah</i> in the middle of the XML tag.
>
> <description>
> There is a a <i>huge</i> storm coming...
> </description>
I think you just need to use <xsl:apply-templates /> everywhere instead
of <xsl:value-of>. This will ensure that the entire input tree is
processed properly by your templates. If you don't want to deal with
some part of the tree, define an empty template:
<xsl:template match="unwanted_data" />
> Is there a way to have a tag interpreted without prior knowledge as to
> its location in the tree? An example would be a forced <BR> in a piece
> of content. I need a block of text + HTML to exist in a single node of
> XML. If a content manager needs to put in a <B>, or <I> or wants to
> have 2 paragraphs in one block, how would the XSL sheet know that you
> have another paragraph or one of these style tags? Thanks for the help,
> it is very much appreciated.
You should probably ask your content manager to use <p> tags. In the
absence of that you could translate all carriage returns to <br> tags,
using Steve Muench's br_replace template (if you can't find it in the
archives, I can send you a copy off-list) - but this is probably not
the right solution if they're entering the text in a text editor.
Hope this helps.
--
Warren Hedley
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list