freelanceprogrammers.org Forum Index » XML / XSL
What is the Best Way to Insert a Blank Space After a String
Joined: 01 May 2005
Posts: 6
What is the Best Way to Insert a Blank Space After a String
I have a openning XML (mainAuthors.xml), a data XML file (data.xml) and
a transformation file (Trans_Authors.xsl). I need to insert a space
after FName,
MName, and LName. I have been playing with this trying to learn how. Will
someone please help me with this.
Here is the openning file,
mainAuthors.xml
<?xml version="1.0" ?><!-- THIS IS THE TITLE SORTATION MAIN PAGE -->
<?xml-stylesheet href="Trans_Authors.xsl" type="text/xsl" ?>
<!-- Some of what follows may not be necessary. -->
<!DOCTYPE html [
<!ENTITY data SYSTEM "./data.xml" >
<!ENTITY % spacer "space" >
<!ELEMENT data (item+) >
<!ELEMENT item ANY >
<!ATTLIST item ref ID #IMPLIED >
<!ELEMENT title (#PCDATA) >
<!ELEMENT edition (#PCDATA) >
<!ELEMENT copyright (#PCDATA) >
<!ELEMENT authors (#PCDATA) >
<!ELEMENT author (FName?, MName?, LName, degree?) >
<!ELEMENT FName (#PCDATA) >
<!ELEMENT MName (#PCDATA) >
<!ELEMENT LName (#PCDATA) >
<!ELEMENT degree (#PCDATA) >
<!ELEMENT publisher (#PCDATA) >
<!ELEMENT isbn (#PCDATA) >
<!ELEMENT lccn (#PCDATA) >
<!ELEMENT price ANY >
<!ELEMENT subject ANY >
]>
<!-- This is a reference to the entity created above. -->
<data></data>
==================================================
Here is a sample of the date.xml file:
<?xml version="1.0" ?>
<?xml-stylesheet href="Trans_Authors.xsl" type="text/xsl" ?>
<!-- <FName></FName><MName></MName><LName></LName><degree></degree> -->
<data>
<item ref="0-672-31763-X">
<title>JavaScript Unleashed</title>
<edition>Third Edition</edition>
<copyright>2000</copyright>
<authors>
<author><FName>Richard</FName><MName></MName><LName>Wagner</LName><degree></degr
ee></author>
<author><FName>R.</FName><MName>Allen</MName><LName>Wyke</LName><degree></degree
></author>
</authors>
<publisher>SAMS</publisher>
<isbn>0-672-31763-X</isbn>
<lccn>99-63993</lccn>
<price>$49.99 USD</price>
<subject>JavaScript Scripting Language - Much of this is about
how to embed JavaScript into HTML:
client-side, server-side, and Microsoft Active Server Pages
(ASP).</subject>
</item>
=========================================
Here is the Trans_Author.xsl:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" >
<xsl:output method="html" indent="yes" />
<xsl:template match="/">
<html>
<link rel="stylesheet" type="text/css" href="my_bookstyle.css" />
<title>MY LIBRARY - SORTED BY AUTHORS</title>
<body>
<table>
<!-- The is the Sortation Option section. -->
<tr align="right"><td>BOOKS SORTED BY AUTHOR</td>
<td><img src="./CharlieChan_bw2.jpg" /></td></tr>
<tr><td align="left"><a href="mainPage.xml" > Sort by Title </a></td>
<td align="right"><a href="mainSubject.xml">Sort by Subject
</a></td></tr>
</table>
<xsl:element name="br" />
<!-- Example of using the document( ) to include a source tree from
a separate XML document -->
<xsl:for-each select="document(`data.xml`)
/data/item/authors/author/LName" >
<xsl:sort data-type="text" order="ascending"
select="normalize-space(ancestor::author/LName)" />
<table>
<xsl:element name="tr">
<xsl:attribute name="class">highlightBlue</xsl:attribute>
<xsl:element name="td">
<p>
<xsl:value-of select="ancestor::author/FName" />
<xsl:value-of select="ancestor::author/MName" />
<xsl:value-of select="ancestor::author/LName" />
<xsl:value-of select="ancestor::author/degree" />
<xsl:value-of select="*/*" />
</p>
</xsl:element> </xsl:element>
</table>
<xsl:value-of select="*/*" /> <!-- Notice how this line of code
ends -->
<xsl:call-template name="aTable" />
</xsl:for-each>
</body>
</html>
</xsl:template>
<!--
I used HTML tags instead of XSLT element tags to display the data in
this table
because it is easier to work with when using a CSS document.
-->
<xsl:template name="aTable">
<xsl:element name="table">
<tr class="highlightBeige"><td>TITLE</td><td><xsl:value-of
select="ancestor::item/title" /> </td></tr>
<tr><td>EDITION</td><td><xsl:value-of
select="ancestor::item/edition" /></td></tr>
<xsl:for-each select="ancestor::authors/author">
<xsl:sort data-type="text" order="ascending"
select="normalize-space(authors/author/LName)" />
<tr><td class="aBorderML">AUTHOR/s</td><td class="aBorderMR">
<xsl:value-of select="." /></td></tr>
</xsl:for-each>
<tr><td>PUBLISHER</td><td><xsl:value-of
select="ancestor::item/publisher" /></td></tr>
<tr><td>ISBN</td><td><xsl:value-of select="ancestor::item/isbn"
/></td></tr>
<tr><td>LCCN</td><td><xsl:value-of select="ancestor::item/lccn"
/></td></tr>
<tr><td>PRICE</td><td><xsl:value-of select="ancestor::item/price"
/></td></tr>
<tr><td class="aBorderBL">SUBJECT</td><td class="aBorderBR"><p>
<xsl:value-of select="ancestor::item/subject" /></p></td></tr>
</xsl:element>
<br />
</xsl:template>
</xsl:stylesheet>
Joined: 13 Jun 2003
Posts: 39
What is the Best Way to Insert a Blank Space After a String
> ... I need to insert a space
> after FName,
> MName, and LName. ...
I haven`t actually tried this, but it should work.
In your Trans_Author.xml file, where you have:
> <xsl:value-of select="ancestor::author/FName" />
> <xsl:value-of select="ancestor::author/MName" />
> <xsl:value-of select="ancestor::author/LName" />
> <xsl:value-of select="ancestor::author/degree" />
Add an xsl:text element between these lines:
> <xsl:value-of select="ancestor::author/FName" />
<xsl:text> </xsl:text>
> <xsl:value-of select="ancestor::author/MName" />
<xsl:text> </xsl:text>
> <xsl:value-of select="ancestor::author/LName" />
<xsl:text> </xsl:text>
> <xsl:value-of select="ancestor::author/degree" />
Hope that helps!
--
Larry Kollar, Senior Technical Writer, ARRIS
"Content creators are the engine that drives
value in the information life cycle."
-- Barry Schaeffer, on XML-Doc
Joined: 01 May 2005
Posts: 6
What is the Best Way to Insert a Blank Space After a String
charlie_chan wrote:
>I have a openning XML (mainAuthors.xml), a data XML file (data.xml) and
>a transformation file (Trans_Authors.xsl). I need to insert a space
>after FName,
>MName, and LName. I have been playing with this trying to learn how. Will
>someone please help me with this.
>
>Here is the openning file,
>mainAuthors.xml
><?xml version="1.0" ?><!-- THIS IS THE TITLE SORTATION MAIN PAGE -->
><?xml-stylesheet href="Trans_Authors.xsl" type="text/xsl" ?>
><!-- Some of what follows may not be necessary. -->
><!DOCTYPE html [
><!ENTITY data SYSTEM "./data.xml" >
><!ENTITY % spacer "space" >
><!ELEMENT data (item+) >
><!ELEMENT item ANY >
><!ATTLIST item ref ID #IMPLIED >
><!ELEMENT title (#PCDATA) >
><!ELEMENT edition (#PCDATA) >
><!ELEMENT copyright (#PCDATA) >
><!ELEMENT authors (#PCDATA) >
><!ELEMENT author (FName?, MName?, LName, degree?) >
> <!ELEMENT FName (#PCDATA) >
> <!ELEMENT MName (#PCDATA) >
> <!ELEMENT LName (#PCDATA) >
> <!ELEMENT degree (#PCDATA) >
><!ELEMENT publisher (#PCDATA) >
><!ELEMENT isbn (#PCDATA) >
><!ELEMENT lccn (#PCDATA) >
><!ELEMENT price ANY >
><!ELEMENT subject ANY >
>]>
><!-- This is a reference to the entity created above. -->
><data></data>
>==================================================
>
>Here is a sample of the date.xml file:
><?xml version="1.0" ?>
><?xml-stylesheet href="Trans_Authors.xsl" type="text/xsl" ?>
><!-- <FName></FName><MName></MName><LName></LName><degree></degree> -->
><data>
><item ref="0-672-31763-X">
> <title>JavaScript Unleashed</title>
> <edition>Third Edition</edition>
> <copyright>2000</copyright>
> <authors>
>
><author><FName>Richard</FName><MName></MName><LName>Wagner</LName><degree></deg
ree></author>
>
><author><FName>R.</FName><MName>Allen</MName><LName>Wyke</LName><degree></degre
e></author>
> </authors>
> <publisher>SAMS</publisher>
> <isbn>0-672-31763-X</isbn>
> <lccn>99-63993</lccn>
> <price>$49.99 USD</price>
> <subject>JavaScript Scripting Language - Much of this is about
>how to embed JavaScript into HTML:
> client-side, server-side, and Microsoft Active Server Pages
>(ASP).</subject>
></item>
>=========================================
>
>Here is the Trans_Author.xsl:
><?xml version="1.0"?>
><xsl:stylesheet version="1.0"
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:msxsl="urn:schemas-microsoft-com:xslt" >
><xsl:output method="html" indent="yes" />
>
><xsl:template match="/">
>
><html>
> <link rel="stylesheet" type="text/css" href="my_bookstyle.css" />
><title>MY LIBRARY - SORTED BY AUTHORS</title>
><body>
> <table>
> <!-- The is the Sortation Option section. -->
> <tr align="right"><td>BOOKS SORTED BY AUTHOR</td>
> <td><img src="./CharlieChan_bw2.jpg" /></td></tr>
> <tr><td align="left"><a href="mainPage.xml" > Sort by Title </a></td>
> <td align="right"><a href="mainSubject.xml">Sort by Subject
></a></td></tr>
> </table>
>
> <xsl:element name="br" />
> <!-- Example of using the document( ) to include a source tree from
>a separate XML document -->
> <xsl:for-each select="document(`data.xml`)
>/data/item/authors/author/LName" >
> <xsl:sort data-type="text" order="ascending"
>select="normalize-space(ancestor::author/LName)" />
> <table>
> <xsl:element name="tr">
> <xsl:attribute name="class">highlightBlue</xsl:attribute>
> <xsl:element name="td">
> <p>
> <xsl:value-of select="ancestor::author/FName" />
> <xsl:value-of select="ancestor::author/MName" />
> <xsl:value-of select="ancestor::author/LName" />
> <xsl:value-of select="ancestor::author/degree" />
> <xsl:value-of select="*/*" />
> </p>
> </xsl:element> </xsl:element>
> </table>
> <xsl:value-of select="*/*" /> <!-- Notice how this line of code
>ends -->
> <xsl:call-template name="aTable" />
> </xsl:for-each>
></body>
></html>
></xsl:template>
>
><!--
>I used HTML tags instead of XSLT element tags to display the data in
>this table
>because it is easier to work with when using a CSS document.
>-->
><xsl:template name="aTable">
><xsl:element name="table">
> <tr class="highlightBeige"><td>TITLE</td><td><xsl:value-of
>select="ancestor::item/title" /> </td></tr>
> <tr><td>EDITION</td><td><xsl:value-of
>select="ancestor::item/edition" /></td></tr>
> <xsl:for-each select="ancestor::authors/author">
> <xsl:sort data-type="text" order="ascending"
>select="normalize-space(authors/author/LName)" />
> <tr><td class="aBorderML">AUTHOR/s</td><td class="aBorderMR">
> <xsl:value-of select="." /></td></tr>
> </xsl:for-each>
> <tr><td>PUBLISHER</td><td><xsl:value-of
>select="ancestor::item/publisher" /></td></tr>
> <tr><td>ISBN</td><td><xsl:value-of select="ancestor::item/isbn"
>/></td></tr>
> <tr><td>LCCN</td><td><xsl:value-of select="ancestor::item/lccn"
>/></td></tr>
> <tr><td>PRICE</td><td><xsl:value-of select="ancestor::item/price"
>/></td></tr>
> <tr><td class="aBorderBL">SUBJECT</td><td class="aBorderBR"><p>
> <xsl:value-of select="ancestor::item/subject" /></p></td></tr>
></xsl:element>
><br />
></xsl:template>
>
></xsl:stylesheet>
>
>
>
>
>Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
Here is how I solved it and the solution worked in both IE6 and FireFox.
<xsl:element name="tr">
<xsl:attribute name="class">highlightBlue</xsl:attribute>
<xsl:element name="td">
<!-- Note how a space was added after each part of a
name. -->
<!-- amp. pound-sign 032; = single space and 160 is nbsp -->
<!-- amp. pd-sign 032; does not work in FireFox -->
<p>
<xsl:value-of select="ancestor::author/FName" />
<xsl:value-of select="` `" />
<xsl:value-of select="ancestor::author/MName" />
<xsl:value-of select="` `" />
<xsl:value-of select="ancestor::author/LName" />
<xsl:value-of select="` `" />
<xsl:value-of select="ancestor::author/degree" />
<xsl:value-of select="*/*" />
</p>
</xsl:element>
</xsl:element>
There maybe a better way.
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







