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

Re: Variables and HTML

Subject: Re: Variables and HTML
From: Carmelo Montanez <carmelo@xxxxxxxx>
Date: Thu, 10 Mar 2005 16:33:20 -0500
html href variable
Hey Jay et all:

Below are my xml (snap shot) and xslt files. What I am attempting to do
(as far as this issue goes) is that for each "name" attribute of the
"linktoterm" element, modify the content of the "definition" element as follows:


"A Ballot prepared or cast by a voter other than at a regular polling place"

Modify to

"A <a href = "Ballot">Ballot</a> prepared or <a href = "cast">cast</a> by a voter other than at a regular polling place."

The relevant code is the "modifyDefinition" template.  Please run it and see
what is generated.  The issue are the entity references inside the variable.

The transformation do other things, but this is the issue I am stock with.

Thanks,
Carmelo

----------------------------------------------- xml file ----------------------------------------

<?xml version="1.0"?>
<glossary>
<term name="Absentee Ballot">
<association type = "voting"/>
<source name= "VSS">
NIST Hanbook 150:2001 NVLAP Procedures and General Requirements
</source>
<definition>
<linkTo termtolink="Ballot"/>
<linkTo termtolink="cast"/>
A Ballot prepared or cast by a voter other than at a regular polling place.
</definition>
</term>


......
------------------------------------------- xslt file --------------------------------------------


<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:preserve-space elements="*"/>

<xsl:param name="heading" />
<xsl:variable name="italicOpen">">&lt;i></xsl:variable>
<xsl:variable name="italicClose">&lt;/i></xsl:variable>
<xsl:variable name="anchorOpen">&lt;a href="</xsl:variable>
<xsl:variable name="anchorClose">&lt;/a></xsl:variable>
<xsl:variable name="varContentOpen">#{</xsl:variable>
<xsl:variable name="varContentClose">}</xsl:variable>
<xsl:template match="glossary">

<html>
<head>
<title>Full Glossary Selected</title>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<a href="http://www.gsa.gov/Portal/home.jsp">
<IMG SRC="gsa_logo.gif" border="0" width="46" height="46" /></a></td>
<td colspan="2" valign="bottom" align="right">
<img src="usgsa.gif" border="0" width="238" height="41" /></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td><img src="header01.gif" alt="spacer"
width="780" height="16" /></td>
</tr>
<tr>
<td><a href="http://xml.gov/index.htm">
<img src="header02.gif" alt="XML Gov Logo"
border="0" width="225" height="40" /></a>
<img src="header03.jpg" alt="flag" width="600"
height="40" /></td>
</tr>
<tr>
<td><img src="header04.gif" alt="spacer"
width="780" height="13" /></td>
</tr>
</tbody>
</table>


       <h1 align="CENTER"><xsl:value-of select="$heading" /></h1>
       <CENTER><A name="index"></A>
       <a href="#A">A</a> |
       <a href="#B">B</a> |
       <a href="#C">C</a> |
       <a href="#D">D</a> |
       <a href="#E">E</a> |
       <a href="#F">F</a> |
       <a href="#G">G</a> |
       <a href="#H">H</a> |
       <a href="#I">I</a> |
       <a href="#J">J</a> |
       <a href="#K">K</a> |
       <a href="#L">L</a> |
       <a href="#M">M</a> |
       <a href="#N">N</a> |
       <a href="#O">O</a> |
       <a href="#P">P</a> |
       <a href="#Q">Q</a> |
       <a href="#R">R</a> |
       <a href="#S">S</a> |
       <a href="#T">T</a> |
       <a href="#U">U</a> |
       <a href="#V">V</a> |
       <a href="#W">W</a> |
       <a href="#X">X</a> |
       <a href="#Y">Y</a> |
       <a href="#Z">Z</a> </CENTER>

<xsl:apply-templates/>

</body>
</html>
</xsl:template>
<xsl:template match="term">
<xsl:variable name="anchor" select = "string(normalize-space(@name))"/>
<xsl:variable name="anchorLetter" select = "substring(normalize-space(@name),1,1)"/>
<DL>
<DT><A name="{$anchor}"></A> <A name="{$anchorLetter}"></A><B><xsl:value-of select = "@name"/></B></DT><br></br>
<xsl:apply-templates select = "definition"/>
</DL>


</xsl:template>
<xsl:template match="definition">
<xsl:call-template name="modifyDefinition">
<xsl:with-param name="counter">1</xsl:with-param>
<xsl:with-param name="outputDefinition" select = "string(normalize-space(.))"/>
<xsl:with-param name="howManyTerms" select="count(linkTo)"/>
</xsl:call-template>


</xsl:template>

<xsl:template name="modifyDefinition">
 <xsl:param name="counter"/>
 <xsl:param name="outputDefinition"/>
 <xsl:param name="howManyTerms"/>

<xsl:choose>
<xsl:when test="$howManyTerms >= 1">
<xsl:variable name="anchor" select="child::linkTo[position()=$counter]/@termtolink"/>
<xsl:variable name="textBeforeWord" select = "substring-before($outputDefinition,$anchor)"/>
<xsl:variable name="textAfterWord" select = "substring-after($outputDefinition,$anchor)"/>


<xsl:variable name="outputDefinition" select="concat($textBeforeWord,$anchorOpen,$anchor,$italicOpen,$anchor,$italicClose,$anchorClose,$textAfterWord)"/>

   <xsl:call-template name="modifyDefinition">
        <xsl:with-param name="counter" select="$counter+1"/>
        <xsl:with-param name="outputDefinition" select="$outputDefinition"/>
        <xsl:with-param name="howManyTerms" select="$howManyTerms - 1"/>
    </xsl:call-template>
        </xsl:when>

<xsl:otherwise>
<DD><xsl:value-of select="$outputDefinition"/></DD> <br></br> <br></br>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
---------------------------------------------------------------------------------------------------


At 01:06 PM 3/10/2005 -0600, JBryant@xxxxxxxxx wrote:
You mention that you need to have entities inside the variable. However,
without seeing more of your XML and XSL and knowing more about what you
want to produce, I don't see the need for the entities inside the
variable. The variable could contain just the href value, in which case
you could do this:

<dd><a href="{$variable1}">Link text (from another variable,
perhaps)</a></dd>

If you show us more about why you need to have the entities in the
variable, perhaps we can offer more help.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)




Carmelo Montanez <carmelo@xxxxxxxx> 03/10/2005 12:46 PM Please respond to xsl-list@xxxxxxxxxxxxxxxxxxxxxx


To xsl-list@xxxxxxxxxxxxxxxxxxxxxx cc

Subject
 Variables and HTML






Folks:


I am sure this been debated before to the ground.  I have
a variable that have entities as part of its contents as in the
following

variable1 = "&lt; A href = ....."

I am trying to output this as html

<dd><xsl:value-of select = "$variable1"/></dd>

The problem is that when I get the HTML, I still have the entities
inside the variables causing the HTML browser to display the wrong thing

My final HML looks something like this:

<DD>A &lt;a href="Ballot"&gt;&lt;i&gt;Ballot&lt;/i&gt;&lt;/a&gt; prepared
or &lt;a href="cast"&gt;&lt;{i&gt;cast&lt;/i&gt;&lt;/a&gt; by a voter
other
than at a regular polling place.</DD>

I will like to have all those entities resolved.  I need to use the
entities inside the
variable because I am doing a lot of manipulations with it.

Thanks,
Carmelo

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.