470,874 Members | 1,573 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,874 developers. It's quick & easy.

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 2984
> 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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mike Kamermans | last post: by
10 posts views Thread by Fred | last post: by
2 posts views Thread by Martijn van Exel | last post: by
3 posts views Thread by Alois Treindl | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.