473,387 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

static text in XSLT

Hi...All,

I am new to XSLT.

I have a XML file which need to be converted to another XML file for
the client. I am using a XSLT .

File 1
------
<client name="abc" address="..." city="..." state=".." zip="....." />

which is to be converted to

File 2
------

<client>
<name>abc</name>
<address>...</address>
<city>...</city>
<state>...</state>
<zip>.....</zip>
</client>
In the XSLT file I am able to parse through the File 1 & get the data to
be printed. But how do I print the tags "<zip>" before the @zip &
"</zip> after the value.

Is there any other easier way.
Regards,

P
Apr 19 '06 #1
5 3168
> In the XSLT file I am able to parse through the File 1 & get the data to
be printed. But how do I print the tags "<zip>" before the @zip &
"</zip> after the value.


Don't think if it as tags before and after. Think if it as elements
wrapped around other elements and/or text. You want to wrap a Literal
Result Element around the retrieved value. For example:

<xsl:template match="client">
<name><xsl:value-of select="@name"/></name>
<!-- ... and so on. -->
</xsl:template>

If you really needed to construct the element on the fly rather than
using a Literal Result Element (because it has a computed name, for
example), you'd use the <xsl:element> directive in much the same way
I've used <name> here.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Apr 19 '06 #2
Hi..Joe,

Thanks a lot!!! I will definitely try it.
Joe Kesselman wrote:
In the XSLT file I am able to parse through the File 1 & get the data
to be printed. But how do I print the tags "<zip>" before the @zip &
"</zip> after the value.


Don't think if it as tags before and after. Think if it as elements
wrapped around other elements and/or text. You want to wrap a Literal
Result Element around the retrieved value. For example:

<xsl:template match="client">
<name><xsl:value-of select="@name"/></name>
<!-- ... and so on. -->
</xsl:template>

If you really needed to construct the element on the fly rather than
using a Literal Result Element (because it has a computed name, for
example), you'd use the <xsl:element> directive in much the same way
I've used <name> here.

Apr 19 '06 #3
Hi..Joe,

I had another question. How do I add line breaks in the new xml file.
Currently it generates the whole XML file in a single line.
For eg :

<client><name>abc</name><address>...</address><city>...</city><state>...</state><zip>.....</zip></client>
Praveen Mohanan wrote:
Hi..Joe,

Thanks a lot!!! I will definitely try it.
Joe Kesselman wrote:
In the XSLT file I am able to parse through the File 1 & get the data
to be printed. But how do I print the tags "<zip>" before the @zip &
"</zip> after the value.


Don't think if it as tags before and after. Think if it as elements
wrapped around other elements and/or text. You want to wrap a Literal
Result Element around the retrieved value. For example:

<xsl:template match="client">
<name><xsl:value-of select="@name"/></name>
<!-- ... and so on. -->
</xsl:template>

If you really needed to construct the element on the fly rather than
using a Literal Result Element (because it has a computed name, for
example), you'd use the <xsl:element> directive in much the same way
I've used <name> here.

Apr 19 '06 #4


Praveen wrote:
I had another question. How do I add line breaks in the new xml file.
Currently it generates the whole XML file in a single line.
For eg :

<client><name>abc</name><address>...</address><city>...</city><state>...</state><zip>.....</zip></client>

<xsl:output method="xml" indent="yes" />
should help.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Apr 19 '06 #5
Martin Honnen wrote:
<xsl:output method="xml" indent="yes" />
should help.


Note that adding whitespace may change the meaning of many kinds of XML
documents. Be sure you know your will accept it before using this feature.

Another solution is to explicitly generate newlines and whitespace where
you want them (and where it's safe), as text content -- typically by
using the <xsl:text> directive.

Another is to not try to format the XML document, but instead to use XML
editors which are aware of document structure and display it nicely
independent of how it appears in the file.

Mike Kay's book on XSLT has a section describing some of the hassles of
whitespace management and how to address them. Worth reading.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Apr 19 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Martin | last post by:
Hallo, can you help me writing a generic xslt transformation (useable with xsql from oracle)? The problem is how to get the escaping characters .... === INPUT-File in.xml <?xml version =...
1
by: Kevin | last post by:
Hi All, Been reading post and thought this might be the right place to ask this. I have some static html pages. On hese pages there is an item that can and does change from day to day. What i...
1
by: ted | last post by:
Looking for advice on the best approach to building static websites. Last year I built a static website with XSLT. The content is in XML and I run it through XSLT to update the site. The XSLT...
2
by: Mike Kamermans | last post by:
I'm having difficulty XSL tranforming some XML of the form <some_element> <jis>1234</jis></some_element> into the xhtml form <img src="jis/1234.gif"/> My initial idea was to use the following...
10
by: Fred | last post by:
Hello, After looking at various CMS tools, either server- (Drupal, Pivot, etc.) or desktop-based (CityDesk, Cute Site Builder), it occured to me that I really didn't need something that...
2
by: Martijn van Exel | last post by:
Hi all, I'm receiving output from a webservice formatted as follows: <?xml version="1.0" encoding="utf-8"?> <DataSet xmlns="http://tempuri.org/adrloc/levering"> <xs:schema...
3
by: Alois Treindl | last post by:
A simple XSL question from a newbie: In an xml document which I transform via xsl into html output, I have some text which I want to be suppressed. The tags looks like this <anchor_ref...
3
by: realmerl | last post by:
Hi All. I'm trying to transform a html document into plain text via xslt. Simple you say! (i hope) I have got it working, by using the magnificent <xsl:value-of select="."/>. This returns the...
1
by: CAM123 | last post by:
I have added: <br><xsl:value-of select="Line" /></br> to my XSLT stylesheet to get a line per repeating block. When I view the output as XML it looks perfect - one line per block. However...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.