Subject: Re: [xsl] variables and inline tags From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Wed, 04 May 2005 17:19:35 -0400 |
<xsl:template match="def/text()"> <!-- when a text node is inside a def, this template overrides the built-in template for text nodes, which simply copies out their values --> <xsl:when test="not(preceding-sibling::node() and starts-with(.,',')"> <!-- truncates the first character if it's a comma and this text node has no preceding siblings --> <xsl:value-of select="substring(., 2)"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="."/> </xsl:otherwise> </xsl:template>
I hope this helps, Wendell
Having problems with variables, applying templates and parsing strings. Been working on it all day and can't seem to wrap my mind around it.
Here is my simplified xml:
<definition> <term>recognized</term> <def>, under the <em>Company Act</em></def> </definition>
What I need to do is substring the def information when it starts with a comma, ie:
with comma <p class="def">"recognized", under the <em>Company Act</em></p>
without comma <p class="def">"recognized" under the <em>Company Act</em></p>
Ok, there's the background. I'm having problems because I'm using a variable to parse out the unwanted space in the with comma example above, then to get the variable I use a value-of statement which promptly drops the <em> tags. Any suggestions or advive would be appreciated.
Here's my simplified xsl:
<!-- Defintion --> <xsl:template match="definition" mode="contentsection"> <p class="def"> <xsl:choose> <xsl:when test="substring(def, 1, 1)=','"> <strong>"<xsl:apply-templates select="term"/>"</strong>, <xsl:variable name="uncommadef"> <xsl:apply-templates select="def"/> </xsl:variable>
<!-- Problem is here -->
<xsl:value-of select="substring($uncommadef, 2)"/>
</xsl:when>
<xsl:otherwise>
<strong>"<xsl:apply-templates
select="term"/>"</strong> <xsl:apply-templates select="def"/>
</xsl:otherwise>
</xsl:choose>
</p>
</xsl:template>
<xsl:template match="term">
<xsl:apply-templates select="text()|strong|em|sup|sub|u|insert|br|eacute"/>
</xsl:template>
<xsl:template match="def">
<xsl:apply-templates select="text()|strong|em|sup|sub|u|insert|br|eacute"/>
</xsl:template>
<!-- End of Definition -->
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] variables and inline tags, David Carlisle | Thread | Re: [xsl] variables and inline tags, Spencer Tickner |
[xsl] How can I get context node in, Jaime Stuardo | Date | RE: [xsl] How can I get context nod, Michael Kay |
Month |