Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the font of text in an XML file using XSLT 1

Status
Not open for further replies.

divinyl

IS-IT--Management
Nov 2, 2001
163
GB
Hi there,

Please bear with me as I am a beginner trying to understand a new system in my company making exstensive use of XML and XSLT.
We basically have an C++ application that sends information to a web application using XML, storing the data in a database. We then have XSLT files which grab this data and transform it into HTML for clients to view through the browser.
In the C++ app, we can change the fonts of the text - so, say for example ive changed it to Comic Sans. When i view the data through the web browser, it is also in comic sans, as it should be. However, if i try and modify the XSLT file so that it displays the font as Arial instead, it doesn't work......

Here is some of the XML file:

<code>

- <ISSUES>
- <ISSUE ID="67108882">
<TITLE>myxslt</TITLE>
<CODE>EX.1</CODE>
<TYPE ID="67108879" />
<TEXTFIELD1><html> <head> <title></title> <meta name="GENERATOR" content="TmXml"> </head> <BODY BGCOLOR="#FFFFFF"><font COLOR="#000000" FACE="Comic Sans MS" SIZE="2" >cvxgxdgsdgsdgsdg sdgsdgs hello <br> </font> </body> </html></TEXTFIELD1>

</code>

and this is the relevant part of the xslt file which grabs the data out of the database and transforms it into html:

<code>

<xsl:template match="/">

<HTML>

<LINK REL='STYLESHEET' HREF="NewTableReportStyles.css"/>

<STYLE>
BR.page { page-break-after: always }
</STYLE>
<HEAD>
<META HTTP-EQUIV="expires" CONTENT="-1"/>
<title><xsl:value-of select="$ReportTitle"/></title>


<STYLE TYPE="text/css">
.header1 { FONT-FAMILY:Arial; font-weight:bold; font-size:8pt }
.header2 { FONT-FAMILY:Arial; font-weight:normal; font-size:8pt }
</STYLE>
</HEAD>
....

<TD>
<span class="header1">--><xsl:value-of select="TM_ISSUE.TEXTFIELD3" disable-output-escaping="yes"/><!--</span>-->&#160;</TD>
</span>

</code>


Can anyone decipher what im trying to do and assist?

Thanks in advance!

Divinyl
 
Have you tried changing the <font face="Comic Sans MS"> to <font face="Arial"> ?

"Ships that pass in the night and speak each other in passing;
Only a signal shown and a distant voice in the darkness;
So on the ocean of life we pass and speak one another,
Only a look and a voice; then darkness again and a silence."
- Henry Wadsworth Longfellow
 
Hi - thanks for the quick reply. The problem is that the xml i have shown you is actually automatically sent from the c++ application to the database - so the text in the database is in comic sans.

Surely a transformation means that the xslt can change whatever is in the XML file?

Thanks for your help

Divinyl
 
Perhaps it's the fact that you have { FONT-FAMILY:... instead of { font-family:... Do you understand? XML doesn't like uppercase. Try changing everything in your XML/XSLT files to lowercase.

"Ships that pass in the night and speak each other in passing;
Only a signal shown and a distant voice in the darkness;
So on the ocean of life we pass and speak one another,
Only a look and a voice; then darkness again and a silence."
- Henry Wadsworth Longfellow
 
I find it difficult to understand the proces:
the xml you posted is not valid xml, because the content of <TEXTFIELD1> is not valid xml. It is HTML, and HTML is less strict then XML: in XML you'd have to close the <META> tag and the <BR> tag. So I wonder how you would ever parse that again with a stylesheet.
Then the xsl you posted makes some html-tags, and then displays TM_ISSUE.TEXTFIELD3. Is that where <TEXTFIELD1> from the xml is supposed to end up? If so, using <xsl:value-of ...> would get rid of all the html-tags in textfield1, and leave you with nothing but the test "cvxgxdgsdgsdgsdg sdgsdgs hello", within your span. I just checked, and it is in Arial indeed (after cleaning up the xml manually, to close the open tags).
If you use <xsl:copy-of select="//TEXTFIELD1/*" /> the html-tags would stay, and you'd end up with somthing that remotely looks like html.
However: it first makes your <span class="header1">, and within that again put the html-tags from textfield1, including the font-tag, and therefore displays comic.
 
You actually were able to fix it? I couldn't have figured out how to correct it without completely rewriting it! Congratulations! I give you a star!

CSS Opinions {
Inline: Messy;
Internal: Wastes space;
External: Bliss;
}
 
Well, thanks, but I didn't 'fix' it: I had to change the xml manually, otherwise my parser wouldn't load it.
In fact, if I would have to display the html that is contained in your xml, and then change the font, I think I'd do a text-replacement on "Comic Sans MS" replace with "Arial": you can't use a stylesheet on invalid xml.
 
Quite true. Quite true indeed.

CSS Opinions {
inline: messy;
internal: wastes-space;
external: bliss;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top