How to Add Attribute in a XML CDATA? XSLT
Posted
by
iCeR
on Stack Overflow
See other posts from Stack Overflow
or by iCeR
Published on 2012-12-18T03:06:19Z
Indexed on
2012/12/18
5:03 UTC
Read the original article
Hit count: 265
xslt
Xml:
<Frames>
<bannerFrame1>
<![CDATA[
<iframe src="https://image.domain.com/promobanner1.html" height="320" width="629" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
]]>
</bannerFrame1>
<bannerFrame2>
<![CDATA[
<iframe src="https://image.domain.com/promobanner2.html" height="320" width="629" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
]]>
</bannerFrame2>
</Frames>
XML: bannerFrame1/iframe CDATA source Value may look like something like this
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<body>
<div>
<img src="banners/banner1.gif" border="0" alt="Banner"/>
</div>
</body>
</html>
XSLT: Im getting the CDATA value of the bannerFrame1
<xsl:template match="/">
<xsl:value-of select="Frames/bannerFrame1" disable-output-escaping="yes" />
</xsl:template>
Im trying to add a google analytic event tracking code on the image from CDATA "bannerFrame1".
How can I add an onclick attribute on <img src="banners/banner1.gif" border="0" alt="Banner">
while getting the CDATA value of <bannerFrame1>
? Is it really possible? Thanks in advance.
Expected output:
<iframe>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<body>
<div>
<img src="banners/banner1.gif" border="0" alt="Banner" onclick ="GoogleEventTracker();"/>
</div>
</body>
</html>
</iframe>
Iframe source:
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" content="no-cache">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.7.2.custom.css">
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="custombanner/jquery.min.js"> </script>
<script type="text/javascript" src="custombanner/jquery.cycle.all.2.74.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
<!--<script type="text/javascript" src="js/custom.js"></script>-->
<title>domain - It's time everyone flies</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="script" http-equiv="Content-Script-Type" content="text/javascript">
<meta name="script" http-equiv="Content-Style-Type" content="text/css">
<!--<script type="text/javascript" src="js/soapclient.js"></script>-->
<style type="text/css">
img, div, a, input
{
behavior: url(iepngfix.htc);
}
#nav
{
float: left;
left: 8px;
margin: 15px;
position: absolute;
top: 235px;
padding-left: 242px; /* for 4 frames */ /*padding-left: 278px; /* for 3 frames */ /*padding-left: 312px; /* for 2 frames */ /*padding-left: 242px; /* for 4 frames */
margin-left: 1px;
margin-right: 1px;
margin-bottom: 1px;
height: 40px; /*background :url("banners/gradient.gif") repeat-x scroll 0 0 transparent;*/
}
#nav li
{
display: block;
float: left;
list-style: none outside none;
margin: 2px;
padding: 2px;
padding-right: 4px;
margin-top: 8px;
width: 25px;
}
#nav a
{
border: 1px solid #ffffff;
display: block;
padding: 0;
width: 25px;
}
#nav img
{
border: medium none;
display: block;
height: 20px;
width: 25px;
opacity: 0.5;
filter: alpha(opacity=50);
}
#nav li.activeLI
{
background: #ff0000;
}
#nav li.activeLI img
{
opacity: 1;
filter: alpha(opacity=100);
}
</style>
</head>
<body marginwidth="0" marginheight="0">
<div class="hero">
<div class="slideshow mainpromo" id="slideshow" style="margin-bottom: 50px;">
<!-- <a href="http://www.domain.com/Pages/SeatSalePromo.aspx" target="_top">
<img src="banners/banner1.gif" border="0" alt="Banner" /></a>-->
<img src="banners/banner1.gif" border="0" alt="Banner">
</div>
<ul id="nav">
</ul>
<div class="rightpane">
<!--<a href="http://www.domain.com" target="_top"><img src="banners/promo-fares.jpg" width="206" height="214" border="0" alt="Thumbnail" /></a>-->
<img src="banners/lite-fares.jpg" width="206" height="214" border="0" alt="Thumbnail">
<a href="https://book.domain.com/Register.aspx" target="_top"><img src="images/registernow.gif" width="203" height="20" border="0" alt="See all Low Fares"></a>
<!--<center><a href="http://www.domain.com/Pages/WebCheck-in.aspx" target="_top"><font size="2" color="#ff6600">Web Check-In</font></a></center>-->
<!--<a href="http://domain.com" target="_blank"><img src="images/topdestinatios_btn.gif" alt="" width="149" height="26" border="0" /></a>-->
</div>
<div id="alerts">
<p>
<strong>Seat Sale Alert! </strong>Be the first to know thePromos. <a target="_top" href="http://www.domain.com/pages/emms-signup.aspx">SUBSCRIBE NOW »</a>
</p>
<p>
<!-- <strong>Seat Sale Availability</strong> Find the best time to travel. <a target="_top"
href="http://www.domain.com/documents/seat_map.pdf">DOWNLOAD PDF »</a>-->
</p>
<div class="clear">
</div>
</div>
<div style="clear: both;">
</div>
<div id="mascot">
<img src="images/mascot.png" alt="">
</div>
<div style="clear: both;">
</div>
</div>
</body></html>
© Stack Overflow or respective owner