...

View Full Version : Resolved XML XSL value-of



kieran491
12-17-2008, 02:42 PM
Hey guys trying to figure out is it possible to use xsl:value-of to pull xml data that also includes other xml data for example



<data>
<html>
<strong>I want to be strong</strong>
</html>
</data>


for example would it be possible to pull html out of data plus the <strong> as a whole?

Thanks Kieran

oesxyl
12-17-2008, 02:46 PM
Hey guys trying to figure out is it possible to use xsl:value-of to pull xml data that also includes other xml data for example



<data>
<html>
<strong>I want to be strong</strong>
</html>
</data>


for example would it be possible to pull html out of data plus the <strong> as a whole?

Thanks Kieran
yes it works but I guess is better to use xsl : copy-of



The xsl:copy-of element can be used to insert a result tree fragment into the result tree, without first converting it to a string as xsl:value-of does (see [7.6.1 Generating Text with xsl:value-of]).

http://zvon.org/xxl/XSLTreference/Output/index.html or see w3c recomandation.

regards

kieran491
12-17-2008, 02:54 PM
Could you provide an example i have tryed this and i am unable to achive any results achiving this

oesxyl
12-17-2008, 02:56 PM
Could you provide an example i have tryed this and i am unable to achive any results achiving this
post your code and I will try to fix it, both xml and xslt files and details about what xslt processor you use.

regards

kieran491
12-17-2008, 02:59 PM
untitled.xml



<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="untitled.xsl"?>
<document>
<title>
Welcome
</title>
<body>
<paragraph>
<strong>
Welcome to , an Australian based game server provider.
</strong>
<br />
We supply the gaming community of Australia with high bandwidth, low latency quality servers at competitive prices.
<br />
We could say we are one of the best server providers in Australia, like all those other companies do but we believe in honesty at . If there is a server problem, we won't beat around the bush, instead we will let you know and get it fixed right away!
<br />
<br />
Everyone wants the best server they can get for their money, but do you know what to look for? Contact our support team and let us know about the plans for your server and we will let you know what kind of services you require, whether we offer it or not.
</paragraph>
<paragraph>
test
</paragraph>
</body>
<section template='index'>
<title>
New Service - Left4Dead
</title>
<body>
<paragraph>
We are excited to announce we will be offering servers for the upcoming Zombie game powered by Valve, called Left4Dead. If you signup for a server with us within 7 days after the Left4Dead launch, you'll get slots for only $3 each! Left4Dead is due to be released on November 17th 2008, you can preorder it now off of Steam.
</paragraph>
</body>
</section>
<section template='index'>
<title>
Site Launch
</title>
<body>
<paragraph>
As many of you have noticed the website has been revamped with a stylish new look, hope you all enjoy it and find it easy enough to navigate.
</paragraph>
</body>
</section>
<section template='faq'>
<title>
How long does it take to setup my server?
</title>
<body>
<paragraph>
While we try to have all servers setup the minute payment has been received, it can take anywhere up to 24 hours for your server to be created. You'll receive an email once it is online containing all the information you need.
</paragraph>
</body>
</section>
</document>


untitled.xsl


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>

</title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="author" content=".com" />
<meta name="description" content="counter strike source servers" />
<meta name="keywords" content=",counter,strike,source,servers,australia,brisbane" />
<meta name="Robots" content="index,follow" />
<link rel="stylesheet" type="text/css" href="css/main.css" media="screen" />
</head>
<body>
<div id="hd">
<ul>
<li id="logo">
<a href="http://.com" title="Go to Home page">

</a>
</li>
</ul>
</div>
<div id="ct">
<div id="ctr">
<dl>
<dt>
<strong>
Counter Strike:Source Special
</strong>
</dt>
<dd>
<br />
Get the &quot;&quot; tag removed from your server name
absolutely free if you signup now!
<br />
<span class="termsapply">
* Terms and conditions may apply
</span>
<br />
</dd>
</dl>
<h2>
Ping Test Server
</h2>
<ol>
<li>
<strong>
Server Name
</strong>
: .com // Ping Test
</li>
<li>
<strong>
Max Players
</strong>
: 4
</li>
<li>
<strong>
Map
</strong>
: de_aztec
</li>
</ol>
<div style="text-align: center">
<a href="steam://connect/202.60.72.168:27015/">
<strong>
Connect
</strong>
</a>
</div>
<br />
<h2>
Random Testimony
</h2>
<div style="text-align: center">
im surprised ur servers run my zombie mod server so good. ty
<br />
<br />
<span class="trueblack">
Written By: REC. John Doyle
</span>
</div>
</div>
<ul id="men">
<li id="m1">
<a href="index.php" title="" class="act">
Home
</a>
</li>
<li id="m2">
<a href="forum.php" title="">
Forums
</a>
</li>
<li id="m3">
<a href="order.php" title="">
Order
</a>
</li>
<li id="m4">
<a href="faq.php" title="">
FAQ
</a>
</li>
<li id="m5">
<a href="contact.php" title="">
Contact
</a>
</li>
</ul>
<div id="ctc">
<h1>
<xsl:value-of select="/document/title" />
</h1>
<xsl:for-each select="/document/body/paragraph">
<p>
<xsl:value-of select="." disable-output-escaping="no" />
</p>
</xsl:for-each>
<xsl:call-template name="index" />
</div>
</div>
<div id="ft">
Copyright 2008 .com.
</div>
</body>
</html>
</xsl:template>

<xsl:template name="index" match="/document/section[@template='index']">
<xsl:for-each select=".">
<h2>
<xsl:value-of select="title" />
</h2>
<xsl:for-each select="body/paragraph">
<p>
<xsl:copy-of select="." />
</p>
</xsl:for-each>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

oesxyl
12-17-2008, 03:26 PM
this will work:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>

</title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="author" content=".com" />
<meta name="description" content="counter strike source servers" />
<meta name="keywords" content=",counter,strike,source,servers,australia,brisbane" />
<meta name="Robots" content="index,follow" />
<link rel="stylesheet" type="text/css" href="css/main.css" media="screen" />
</head>
<body>
<div id="hd">
<ul>
<li id="logo">
<a href="http://.com" title="Go to Home page">

</a>
</li>
</ul>
</div>
<div id="ct">
<div id="ctr">
<dl>
<dt>
<strong>
Counter Strike:Source Special
</strong>
</dt>
<dd>
<br />
Get the &quot;&quot; tag removed from your server name
absolutely free if you signup now!
<br />
<span class="termsapply">
* Terms and conditions may apply
</span>
<br />
</dd>
</dl>
<h2>
Ping Test Server
</h2>
<ol>
<li>
<strong>
Server Name
</strong>
: .com // Ping Test
</li>
<li>
<strong>
Max Players
</strong>
: 4
</li>
<li>
<strong>
Map
</strong>
: de_aztec
</li>
</ol>
<div style="text-align: center">
<a href="steam://connect/202.60.72.168:27015/">
<strong>
Connect
</strong>
</a>
</div>
<br />
<h2>
Random Testimony
</h2>
<div style="text-align: center">
im surprised ur servers run my zombie mod server so good. ty
<br />
<br />
<span class="trueblack">
Written By: REC. John Doyle
</span>
</div>
</div>
<ul id="men">
<li id="m1">
<a href="index.php" title="" class="act">
Home
</a>
</li>
<li id="m2">
<a href="forum.php" title="">
Forums
</a>
</li>
<li id="m3">
<a href="order.php" title="">
Order
</a>
</li>
<li id="m4">
<a href="faq.php" title="">
FAQ
</a>
</li>
<li id="m5">
<a href="contact.php" title="">
Contact
</a>
</li>
</ul>
<div id="ctc">
<xsl:apply-templates select="document/section[@template = 'index']"/>
</div>
</div>
<div id="ft">
Copyright 2008 .com.
</div>
</body>
</html>
</xsl:template>

<xsl:template match="section">
<h2>
<xsl:value-of select="title" />
</h2>
<xsl:apply-templates select="body/paragraph"/>
</xsl:template>

<xsl:template match="paragraph">
<p>
<xsl:copy-of select="." />
</p>
</xsl:template>


</xsl:stylesheet>

some suggestion:
- xslt is a declaratiive language not procedural, there are only few cases when you need to use for-each
- in order to produce valid markup you must change the xsl: output for what you intend to do xhtml not html 4.0, and probably you must use omit-xml-declaraion

the only changes are to the end of the file:
- replace call-template with apply-template
- change last template and remove for-each
- in first template you match for "/" so inside you must use xpath like document/.... not /document

best regards

kieran491
12-17-2008, 03:31 PM
Thanks for that really helped :)

oesxyl
12-17-2008, 03:32 PM
Thanks for that really helped :)
you are welcome, :)

best regards

byuhobbes85
12-17-2008, 11:57 PM
Oesxyl, I thought I was pretty good with XML, but the more I read your posts around the forum, the more I realize how little I know. Thanks for this post, it helped me solve a problem as well!

oesxyl
12-18-2008, 05:59 AM
Oesxyl, I thought I was pretty good with XML, but the more I read your posts around the forum, the more I realize how little I know. Thanks for this post, it helped me solve a problem as well!
you are welcome, :)

I post this link few times on cf, is a very good resource:

http://www.jenitennison.com/xslt/index.html

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum