style tag in xslt not rendering - css

Here is my xslt:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" omit-xml-declaration="yes" doctype-system="about:legacy-compat" />
<xsl:template match="/">
<html>
<xsl:call-template name="header">
<xsl:with-param name="title">Strip Club List - Top 100
<xsl:choose>
<xsl:when test="/*/general/viewmethod='numcomments'">
Highest Number of Comments
</xsl:when>
<xsl:when test="/*/general/viewmethod='numreviews'">
Highest Number of Reviews
</xsl:when>
<xsl:when test="/*/general/viewmethod='highestreviews'">
Highest Rating
</xsl:when>
<xsl:when test="/*/general/viewmethod='numlikes'">
Highest Number of Likes
</xsl:when>
<xsl:when test="/*/general/viewmethod='numdislikes'">
Highest Number of Dislikes
</xsl:when>
<xsl:when test="/*/general/viewmethod='numfollowers'">
Highest Number of Followers
</xsl:when>
</xsl:choose>
<xsl:value-of select="/*/locations/name" /></xsl:with-param>
<xsl:with-param name="stylesheets">fonts.css,core.css,state.css,top.css</xsl:with-param>
<xsl:with-param name="scripts">core.js,state.js</xsl:with-param>
<xsl:choose>
<xsl:when test="/*/general/viewmethod='numcomments'">
<style>
.linked_location .rating {
right: 110px;
}
</style>
</xsl:when>
<xsl:when test="/*/general/viewmethod='numreviews'">
<style>
.linked_location .rating {
right: 100px;
}
</style>
</xsl:when>
</xsl:choose>
</xsl:call-template>
<body>
<div id="body"></div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Its being rendered in the head of the html document. The problem is that its not rendering onto the page. I believe it has to do with using style tags in an XSLT document.
XML:
<root>
<general>
<viewmethod>numreviews</viewmethod>
</general>
</root>
I also just tried:
<xsl:choose>
<xsl:when test="/*/general/viewmethod='numcomments'">
<style>
.linked_location .rating {
right: 110px;
}
</style>
</xsl:when>
<xsl:when test="/*/general/viewmethod='numreviews'">
<style>
.linked_location .rating {
right: 100px;
}
</style>
</xsl:when>
<xsl:when test="/*/general/viewmethod='highestreviews'">
<style>
.linked_location .rating {
right: 100px;
}
</style>
</xsl:when>
<xsl:when test="/*/general/viewmethod='numlikes'">
<style>
.linked_location .rating {
right: 90px;
}
</style>
</xsl:when>
<xsl:when test="/*/general/viewmethod='numdislikes'">
<style>
.linked_location .rating {
right: 90px;
}
</style>
</xsl:when>
<xsl:when test="/*/general/viewmethod='numfollowers'">
<style>
.linked_location .rating {
right: 90px;
}
</style>
</xsl:when>
</xsl:choose>
here is my header template
<xsl:template name="header">
<xsl:param name="title" />
<xsl:param name="keywords" />
<xsl:param name="description" />
<xsl:param name="stylesheets" />
<xsl:param name="scripts" />
<xsl:param name="emp" />
<head>
<xsl:if test="string-length($keywords) > 0"><meta name="keywords" content="{$keywords}" /></xsl:if>
<xsl:if test="string-length($description) > 0"><meta name="description" content="{$description}" /></xsl:if>
<xsl:if test="string-length($stylesheets) > 0"><xsl:call-template name="headercss"><xsl:with-param name="stylesheets" select="$stylesheets" /></xsl:call-template></xsl:if>
<xsl:if test="string-length($scripts) > 0"><xsl:call-template name="headerjs"><xsl:with-param name="scripts" select="$scripts" /></xsl:call-template></xsl:if>
<script src="http://domain/www/delivery/i.php?id=13&blockcampaign=1&target=_blank"></script>
<xsl:if test="$emp > 0">
<link rel="stylesheet" type="text/css" href="/emp/style.css" />
<script src="/emp/gl.js"></script>
<script src="/emp/tween.js"></script>
<script src="/emp/emp.js"></script>
</xsl:if>
<title><xsl:value-of select="$title" /></title>
</head>
</xsl:template>
thanks

As mentioned in comments xsl:choose can not be a child of xsl:call-template. See http://www.w3.org/TR/xslt#named-templates for the syntax. It is possible that the XSLT processor you are using is simply ignoring the xsl:choose in this case, rather than throwing an error.
What you probably need to do, is add a style parameter to your header template, and then pass in the style using xsl:with-param in a similar manner to the other parameters.
Try this XSLT as a slimmed down example:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" omit-xml-declaration="yes" doctype-system="about:legacy-compat" />
<xsl:template match="/">
<html>
<xsl:call-template name="header">
<xsl:with-param name="title">Test</xsl:with-param>
<xsl:with-param name="keywords" select="/root/general/viewmethod" />
<xsl:with-param name="style">
<xsl:choose>
<xsl:when test="/*/general/viewmethod='numcomments'">
<style>
.linked_location .rating {
right: 110px;
}
</style>
</xsl:when>
<xsl:when test="/*/general/viewmethod='numreviews'">
<style>
.linked_location .rating {
right: 100px;
}
</style>
</xsl:when>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
<body>
<div id="body"></div>
</body>
</html>
</xsl:template>
<xsl:template name="header">
<xsl:param name="title" />
<xsl:param name="keywords" />
<xsl:param name="style" />
<head>
<xsl:if test="string-length($keywords) > 0"><meta name="keywords" content="{$keywords}" /></xsl:if>
<xsl:copy-of select="$style" />
<title><xsl:value-of select="$title" /></title>
</head>
</xsl:template>
</xsl:stylesheet>

Related

Using an xslt file to turn xml file into svg?

I need to make an xslt that turns my xml file into an svg.
The can't load the desired image, but it's basically a bar graph with a title at the top that says "Fall 2018 enrollment" and the height of each bar in the graph is based on the enrollment element in the xml file (so it's not hard coded).
I've been fiddling around with it a bit but I really don't know what to do.
This is the xml file:
<?xml version="1.0" encoding="UTF-8"?>
<courses>
<course number="341" credits="4.0">
<title>Data Structures</title>
<section number="01" delivery="Classroom">
<enrollment>15</enrollment>
<room>EA244</room>
<instructor>
<first>Nicole</first>
<last>Anderson</last>
</instructor>
</section>
<section number="02" delivery="Online">
<enrollment>10</enrollment>
<instructor>
<first>Nicole</first>
<last>Anderson</last>
</instructor>
<instructor>
<first>Chi-Cheng</first>
<last>Lin</last>
</instructor>
</section>
<section number="03" delivery="Classroom">
<enrollment>12</enrollment>
<room>SH102</room>
<instructor>
<first>Mark</first>
<last>Funk</last>
</instructor>
</section>
</course>
<course number="368" credits="4.0">
<title>Introduction to Bioinformatics</title>
<section number="01" delivery="Classroom">
<enrollment>9</enrollment>
<room>AT102</room>
<instructor>
<first>Chi-Cheng</first>
<last>Lin</last>
</instructor>
<instructor>
<first>Mingrui</first>
<last>Zhang</last>
</instructor>
</section>
</course>
<course number="375" credits="4.0">
<title>Computer Systems</title>
<section number="01" delivery="ITV">
<enrollment>18</enrollment>
<room>EA244</room>
<instructor>
<first>Chi-Cheng</first>
<last>Lin</last>
</instructor>
</section>
</course>
<course number="385" credits="3.0">
<title>Applied Database Management Systems</title>
<section number="01" delivery="Classroom">
<enrollment>26</enrollment>
<room>ST108</room>
<instructor>
<first>Nicole</first>
<last>Anderson</last>
</instructor>
</section>
</course>
<course number="413" credits="3.0">
<title>Advanced Networking</title>
<section number="01" delivery="Online">
<enrollment>10</enrollment>
<instructor>
<first>Chi-Cheng</first>
<last>Lin</last>
</instructor>
</section>
</course>
</courses>

This is my attempt at an xslt.
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/2000/svg">
<xsl:output indent="yes" cdata-section-elements="style"/>
<xsl:param name="width" select="40"/><!--width of bars-->
<xsl:param name="space" select="10"/><!--space between bars-->
<xsl:variable name="max-y" select="//enrollment[not(//enrollement > .)[1]"/>
<xsl:template match="courses">
<svg>
<defs>
<style type="text/css"><![CDATA[
g.bar text {
font-family: Arial;
text-anchor: middle;
fill: white;
}
g.bar rect {
fill: blue;
}
]]>
</style>
</defs>
<g transform="translate(10,10)">
<xsl:apply-templates select="course"/>
</g>
</svg>
</xsl:template>
<xsl:template match="course">
<xsl:variable name="prev-course" select="preceding-sibling::course "/>
<g class="course" id="course-{position()}" transform="translate({
count($prev-course/section) * ($width + $space)
+ count($prev-course) * $space
})">
<xsl:apply-templates select="section" />
</g>
</xsl:template>
<xsl:template match="section">
<xsl:variable name="prev-section" select="preceding-sibling::section "/>
<g class="section" id="section-{position()}" transform="translate({
count($prev-section/enrollment) * ($width + $space)
+ count($prev-section) * $space
})">
<xsl:apply-templates select="enrollment" />
</g>
</xsl:template>
<xsl:template match="enrollment">
<xsl:variable name="idx" select="count(preceding-sibling::enrollment)" />
<xsl:variable name="pos" select="$idx * ($width + $space)" />
<g class="bar">
<rect x="{$pos}" y="{$max-y - .}" height="{.}" width="{$width}" />
<text x="{$pos + $width div 2.0}" y="{$max-y - $space}">
<xsl:value-of select="."/>
</text>
</g>
</xsl:template>
</xsl:stylesheet>
The line <xsl:variable name="max-y" select="//enrollment[not(//enrollement > .)[1]"/> lacks a closing brackets, I guess you want <xsl:variable name="max-y" select="//enrollment[not(//enrollement > .)][1]"/>.
I would probably use
<xsl:variable name="max-y">
<xsl:for-each select="//enrollment">
<xsl:sort select="." data-type="number" order="descending"/>
<xsl:if test="position() = 1">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
however.

Get last item in xslt

I have this piece of XSLT
<xsl:template match="/">
<xsl:variable name="boxes" select="$currentPage/boxes/descendant::nodeId [text() != '']" />
<xsl:if test="count($boxes) > 0">
<div id="boxContainer">
<ul class="noList" id="frontBoxes">
<xsl:for-each select="$boxes">
<xsl:variable name="node" select="umbraco.library:GetXmlNodeById(.)" />
<xsl:variable name="imageNodes" select="umbraco.library:Split($node/descendant::boxImage, ',')" />
<xsl:for-each select="$imageNodes/descendant::value">
<xsl:variable name="image" select="umbraco.library:GetMedia(.,0)" />
<li>
<a class="boxLink">
<xsl:attribute name="href">
<xsl:value-of select="umbraco.library:NiceUrl($node/descendant::boxLink)" />
</xsl:attribute>
<xsl:value-of select="$node/#nodeName" />
</a>
<img src="{Eksponent.CropUp:Url($image/umbracoFile, 'frontBoxes')}" width="{$image/umbracoWidth}" height="{$image/umbracoHeight}" alt="" />
<xsl:value-of select="$node/descendant::bodyText" />
</li>
</xsl:for-each>
</xsl:for-each>
</ul>
</div>
</xsl:if>
</xsl:template>
If runs through a maximum and minimum of for front page boxes with an image, text and a link.
How can I get the last item so that I can output class="last" in the last <li>
I have tried with <xsl:if test="position()"> inside the last for-each but that doesn't work as intended.
use
<xsl:choose>
<xsl:when test="position()=last()">
<!-- set class="list" -->
</xsl:when>
<xsl:otherwise>
<!-- without class="list" -->
</xsl:otherwise>
</xsl:choose>

how to create search control in tridion site?

I've created a tridion web site, now i want to add some search control like Google custom search, is there any option provide by tridion for the same?
my option :
i have to create a user contol and implement Google custom search in there then render it on my pages. or any other approach'd be better.
search control (contain text box and a search button) should be able to search text.
search results should be formatted as search engines do.
When you say Google, are you talking about the Google Search Appliance (GSA)?
Assuming that is the case: You seem to have done quite a lot of work with XSLT, so in my opinion the easiest way to do thes is have your usercontrol call the XML API for the GSA with the relevant query, and simply transform the response with XSLT. This prevents you from having to recompile the control when you need layout changes, and you can publish the XSLT from Tridion.
I use the following XSLT to generate the search results on this page http://medicine.yale.edu/search.aspx?q=test&x=0&y=0&site=YSM_School_of_Medicine
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" omit-xml-declaration="yes"/>
<xsl:param name="SITE_CATALOG"/>
<xsl:param name="SITE_NAME"/>
<xsl:param name="MAX_PAGES_IN_NAVIGATION">10</xsl:param>
<xsl:param name="TOTALNUMBER" select="/GSP/RES/M"/>
<xsl:param name="QUERY" select="/GSP/PARAM[#name='q']/#value"/>
<xsl:param name="SEARCHED_SITE_CATALOG" select="/GSP/PARAM[#name='site']/#value"/>
<xsl:template match="/">
<xsl:variable name="STARTNUMBER" select="/GSP/RES/#SN"/>
<xsl:variable name="ENDNUMBER" select="/GSP/RES/#EN"/>
<xsl:variable name="TIMER" select="/GSP/TM"/>
<!--begin search results -->
<div class="google-search-form bordered-box shaded-f5 padded-20">
<xsl:call-template name="WriteSearchForm"/>
</div>
<xsl:if test="/GSP/Spelling">
<p>Did you mean <a href="?q={/GSP/Spelling/Suggestion/#q}&site={/GSP/PARAM[#name='site']/#value}">
<xsl:value-of select="/GSP/Spelling/Suggestion/#q"/>
</a>?</p>
</xsl:if>
<div id="search-results-pagination">
<xsl:for-each select="/GSP/RES/R">
<xsl:choose>
<xsl:when test="#L='2'">
<div class="grouped-search-result">
<h4>
<a href="{U}">
<xsl:value-of select="T" disable-output-escaping="yes"/>
</a>
</h4>
<p class="search-result-body">
<xsl:value-of select="S" disable-output-escaping="yes"/>
</p>
<p class="gray95">
<span class="green">
<xsl:choose>
<xsl:when test="string-length(U) > 88">
<xsl:value-of select="substring(U, 0, 88)"/>...
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="U"/>
</xsl:otherwise>
</xsl:choose>
</span>
</p>
<p>
<a href="?as_sitesearch={HN/#U}&q={$QUERY}&site={$SITE_CATALOG}" class="more-results-link">
[ <span>
More results from <xsl:value-of select="HN/#U"/>
</span> ]
</a>
</p>
</div>
</xsl:when>
<xsl:otherwise>
<div class="pagination-element search-result">
<h4><a href="{U}">
<xsl:call-template name="WriteMimeTypeIndicator">
<xsl:with-param name="RESULT" select="."/>
</xsl:call-template>
<xsl:value-of select="T" disable-output-escaping="yes"/>
</a></h4>
<p class="search-result-body">
<xsl:value-of select="S" disable-output-escaping="yes"/>
</p>
<p>
<span class="green">
<xsl:choose>
<xsl:when test="string-length(U) > 92">
<xsl:value-of select="substring(U, 0, 92)"/>...
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="U"/>
</xsl:otherwise>
</xsl:choose>
</span> - <xsl:value-of select="HAS/C/#SZ"/>
</p>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</div>
<hr class="dashed" />
<xsl:call-template name="WritePageNavigation"/>
<!--<div id="pagination-controls" class="pagination-controls float-rt"></div>-->
<!-- end pagination-controls -->
<div class="results-footer-notes">
<p class="small-gray95">Note: This search service may return results that are not approved by Yale University, or results that may not reflect the official views of Yale University.</p>
</div>
<div class="clear"></div>
<div class="google-search-form bordered-box shaded-f5 padded-20 big-margin-top">
<xsl:call-template name="WriteSearchForm"/>
</div>
<!-- end search results -->
</xsl:template>
<xsl:template name="WritePageNavigation">
<xsl:variable name="RESULTS_ON_THIS_PAGE" select="count(/GSP/RES/R)"/>
<xsl:variable name="TOTAL_RESULT_COUNT" select="/GSP/RES/M"/>
<xsl:variable name="TOTAL_PAGES" select="ceiling($TOTAL_RESULT_COUNT div $RESULTS_ON_THIS_PAGE)"/>
<xsl:variable name="CURRENT_PAGE" select="floor((/GSP/RES/#SN) div $RESULTS_ON_THIS_PAGE) + 1"/>
<xsl:variable name="START_RESULT" select="/GSP/RES/#SN"/>
<!--
Results On This Page: <xsl:value-of select="$RESULTS_ON_THIS_PAGE"/>
<br/>
Total Results: <xsl:value-of select="$TOTAL_RESULT_COUNT"/>
<br/>
Total Pages: <xsl:value-of select="$TOTAL_PAGES"/>
<br/>
Current Page: <xsl:value-of select="$CURRENT_PAGE"/>
<br/>
Start Result: <xsl:value-of select="$START_RESULT"/>
<br/>
Start Navigation Page: <xsl:value-of select="$CURRENT_PAGE - ($MAX_PAGES_IN_NAVIGATION div 2)"/>
-->
<xsl:if test="$TOTAL_PAGES > 1">
<ul class="google-search-pagination">
<xsl:if test="$CURRENT_PAGE > 1">
<li class="pagination-previous">
Previous
</li>
</xsl:if>
<xsl:call-template name="WritePaging">
<xsl:with-param name="CURRENT_PAGE" select="$CURRENT_PAGE"/>
<xsl:with-param name="NEXT_PAGE_START" select="$RESULTS_ON_THIS_PAGE + 1"/>
<xsl:with-param name="TOTAL_RESULTS" select="$TOTAL_RESULT_COUNT"/>
<xsl:with-param name="RESULTS_ON_PAGE" select="$RESULTS_ON_THIS_PAGE"/>
<xsl:with-param name="START_PAGE">
<xsl:choose>
<xsl:when test="($CURRENT_PAGE - ($MAX_PAGES_IN_NAVIGATION div 2)) > 0">
<xsl:value-of select="$CURRENT_PAGE - ($MAX_PAGES_IN_NAVIGATION div 2)"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
<xsl:with-param name="END_PAGE">
<xsl:choose>
<xsl:when test="($CURRENT_PAGE - ($MAX_PAGES_IN_NAVIGATION div 2)) > 0">
<xsl:value-of select="$MAX_PAGES_IN_NAVIGATION + $CURRENT_PAGE - floor($MAX_PAGES_IN_NAVIGATION div 2) - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$MAX_PAGES_IN_NAVIGATION"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
<li class="pagination-next">
Next
</li>
</ul>
</xsl:if>
</xsl:template>
<xsl:template name="WritePaging">
<xsl:param name="NEXT_PAGE_START"/>
<xsl:param name="RESULTS_ON_PAGE"/>
<xsl:param name="TOTAL_RESULTS"/>
<xsl:param name="CURRENT_PAGE"/>
<xsl:param name="START_PAGE"/>
<xsl:param name="END_PAGE"/>
<!--
NEXT_PAGE_START: <xsl:value-of select="$NEXT_PAGE_START"/><br/>
RESULTS_ON_PAGE: <xsl:value-of select="$RESULTS_ON_PAGE"/><br/>
TOTAL_RESULTS: <xsl:value-of select="$TOTAL_RESULTS"/><br/>
CURRENT_PAGE: <xsl:value-of select="$CURRENT_PAGE"/><br/>
START_PAGE: <xsl:value-of select="$START_PAGE"/><br/>
END_PAGE: <xsl:value-of select="$END_PAGE"/><br/>
-->
<li>
<xsl:if test="$CURRENT_PAGE = $START_PAGE">
<xsl:attribute name="class">selected</xsl:attribute>
<a href="#">
<xsl:value-of select="$START_PAGE"/>
</a>
</xsl:if>
<xsl:if test="$CURRENT_PAGE != $START_PAGE">
<a href="?q={/GSP/PARAM[#name='q']/#value}&start={($START_PAGE - 1)*$RESULTS_ON_PAGE}&site={/GSP/PARAM[#name='site']/#value}">
<xsl:value-of select="$START_PAGE"/>
</a>
</xsl:if>
</li>
<xsl:if test="$START_PAGE < $END_PAGE">
<xsl:if test="$NEXT_PAGE_START < $TOTAL_RESULTS">
<xsl:call-template name="WritePaging">
<xsl:with-param name="NEXT_PAGE_START" select="$NEXT_PAGE_START + $RESULTS_ON_PAGE"/>
<xsl:with-param name="TOTAL_RESULTS" select="$TOTAL_RESULTS"/>
<xsl:with-param name="RESULTS_ON_PAGE" select="$RESULTS_ON_PAGE"/>
<xsl:with-param name="START_PAGE" select="$START_PAGE + 1"/>
<xsl:with-param name="CURRENT_PAGE" select="$CURRENT_PAGE"/>
<xsl:with-param name="END_PAGE" select="$END_PAGE"/>
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template name="WriteSearchForm">
<form name="gs" method="GET" action="#">
<p class="wrapper">
<input type="text" name="q" maxlength="256" value="{$QUERY}" class="google-search-keywords"/>
<select name="site" class="google-search-site">
<option value="{$SITE_CATALOG}">
<xsl:if test="$SEARCHED_SITE_CATALOG = $SITE_CATALOG">
<xsl:attribute name="selected">true</xsl:attribute>
</xsl:if>
<xsl:value-of select="$SITE_NAME" disable-output-escaping="yes"/>
</option>
<option value="Yale_University">---------------</option>
<option value="YSM_School_of_Medicine">
<xsl:if test="$SEARCHED_SITE_CATALOG = 'YSM_School_of_Medicine'">
<xsl:attribute name="selected">true</xsl:attribute>
</xsl:if>
School of Medicine
</option>
<option value="Yale_Medical_Group">
<xsl:if test="$SEARCHED_SITE_CATALOG = 'Yale_Medical_Group'">
<xsl:attribute name="selected">true</xsl:attribute>
</xsl:if>
Yale Medical Group
</option>
<option value="Yale_New_Haven_Hospital">
<xsl:if test="$SEARCHED_SITE_CATALOG = 'Yale_New_Haven_Hospital'">
<xsl:attribute name="selected">true</xsl:attribute>
</xsl:if>
Yale-New Haven Hospital
</option>
<option value="Medical_Center">
<xsl:if test="$SEARCHED_SITE_CATALOG = 'Medical_Center'">
<xsl:attribute name="selected">true</xsl:attribute>
</xsl:if>
Medical Center (all)
</option>
<option value="Medical_Library">
<xsl:if test="$SEARCHED_SITE_CATALOG = 'Medical_Library'">
<xsl:attribute name="selected">true</xsl:attribute>
</xsl:if>
Medical Library
</option>
<option value="Yale_University">---------------</option>
<option value="Yale_Libraries">
<xsl:if test="$SEARCHED_SITE_CATALOG = 'Yale_Libraries'">
<xsl:attribute name="selected">true</xsl:attribute>
</xsl:if>
Yale Libraries
</option>
<option value="Finance_and_Administration">
<xsl:if test="$SEARCHED_SITE_CATALOG = 'Finance_and_Administration'">
<xsl:attribute name="selected">true</xsl:attribute>
</xsl:if>
Finance & Admin
</option>
<option value="Human_Resources">
<xsl:if test="$SEARCHED_SITE_CATALOG = 'Human_Resources'">
<xsl:attribute name="selected">true</xsl:attribute>
</xsl:if>
Human Resources
</option>
<option value="ITS">
<xsl:if test="$SEARCHED_SITE_CATALOG = 'ITS'">
<xsl:attribute name="selected">true</xsl:attribute>
</xsl:if>
Information Technology
</option>
<option value="Yale_University">
<xsl:if test="$SEARCHED_SITE_CATALOG = 'Yale_University'">
<xsl:attribute name="selected">true</xsl:attribute>
</xsl:if>
Yale University
</option>
</select>
<button type="submit" value="submit" class="google-search-button theme-background">
<img src="/files/images/button_search_icon_translucent_sm.png" />Google Search
</button>
</p>
<p class="no-space-bottom float-rt" style="margin-right:50px;">
<a href="http://www.yale.edu/its/web/search/tips.html" class="search-tips">
<img src="/files/images/icon_question.gif" alt="" style="vertical-align:middle" /> Search Tips
</a>
</p>
<p class="no-space-bottom gray95">
Results <span class="green">
<xsl:value-of select="/GSP/RES/#SN"/>
</span> - <span class="green">
<xsl:value-of select="/GSP/RES/#EN"/>
</span> of about <span class="green"><xsl:value-of select="$TOTALNUMBER"/></span> for <strong><xsl:value-of select="$QUERY"/></strong>
</p>
</form>
</xsl:template>
<xsl:template name="WriteMimeTypeIndicator">
<xsl:param name="RESULT"/>
<xsl:choose>
<xsl:when test="not($RESULT/#MIME)"></xsl:when>
<xsl:when test="$RESULT/#MIME = 'application/msword'">[DOC] </xsl:when>
<xsl:when test="$RESULT/#MIME = 'application/octet-stream'">TEST OPTIONS</xsl:when>
<xsl:when test="$RESULT/#MIME = 'application/pdf'">[PDF] </xsl:when>
<xsl:otherwise>TODO:<xsl:value-of select="$RESULT/#MIME"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

CSS style and XSLT?

If I select a DIV tag in a XHTML file with XSLT, like //*[#id='background'] How do I add a style, like a background color or other CSS styles like borders to the DIV? And if I have a list inside the DIV ID=background, how can I style the list, like removing the bullets? :)
This is really easy with XSLT. For instance, your input is:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title></title>
</head>
<body>
<div id="background">
<ul style="list-style-type: bullet">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</div>
</body>
</html>
You can use the identity transform to copy the input XML as is, and override the nodes of interest:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:x="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="x">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*" />
</xsl:copy>
</xsl:template>
<xsl:template match="x:div[#id='background']">
<xsl:copy>
<xsl:attribute name="style">
<xsl:text>border-style:solid;border-width:medium</xsl:text>
</xsl:attribute>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="x:ul[ancestor::*
[name()='div' and #id='background']]/#style">
<xsl:attribute name="style">
<xsl:text>list-style-type: none</xsl:text>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
The output will be:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title></title>
</head>
<body>
<div style="border-style:solid;border-width:medium" id="background">
<ul style="list-style-type: none">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</div>
</body>
</html>

XML - Help removing nodes being published

Any help much appreciated on this.
I'd like to remove certain nodes from being published in a feed from an external xml file, which I've styled with xslt. Here is the feed:http://www.wcwg.info/feeds/localevents.aspx?a=00392&p=CM159EH&m=20.
The nodes I would like to remove are:
Local Events posted to WhereCanWeGo.com.00392CM15
9EH31/10/1007/11/1010001111111111111111111031
October
2010http://www.wherecanwego.com/events/signin.aspxww.wherecanwego.com/events/signin.aspx
Could anybody be kind enough to direct me how to remove these initial nodes (parameters)? They are the postcode, account number, feed URL etc.
I'm desperate to get this finished, but it's the final hurdle! Many thanks in advance for anyone who responds...
The stylesheet (fragment)
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="item">
<div class="local_events">
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="Venue"/>
<xsl:apply-templates select="Times"/>
<xsl:apply-templates select="Dates"/>
<xsl:apply-templates select="DetailsURL"/>
</div><div style="height:1px;border-bottom:1px dotted #cfcfcf;"></div>
</xsl:template>
<xsl:template match="title">
<h2><a class="title" target="_blank" rel="nofollow" href="{../DetailsURL}"><xsl:value-of select="."/></a></h2>
</xsl:template>
<xsl:template match="Venue">
<span>Location: </span>
<xsl:value-of select="."/>
<br />
</xsl:template>
<xsl:template match="Times">
<span>Details: </span>
<xsl:value-of select="."/>
<br />
</xsl:template>
<xsl:template match="Dates">
<span>Dates: </span>
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="DetailsURL">
<a style="font-weight:normal;margin-left:0.5em;" target="_blank" rel="nofollow" href="{.}"><xsl:text>Full details...</xsl:text></a>
</xsl:template>
From your poorly formulated question and analyzing the feed, it seems that you want to get rid of all children of the top (LocalEvents) node that are not named item.
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*/*[not(self::item)]"/>
</xsl:stylesheet>
when applied on the provided feed (http://www.wcwg.info/feeds/localevents.aspx?a=00392&p=CM159EH&m=20), produces the wanted result.
Do note: how the wanted elements are deleted (not processed, ignored) by an empty template matching them and overriding the identity rule that is used to copy the rest of the nodes "as-is".
If you already use an XSLT stylesheet that does not do exactly what you want then please post the stylesheet or a link to it.
[edit]
In your posted stylesheet change
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
to
<xsl:template match="/">
<xsl:apply-templates select="//item"/>
</xsl:template>
This has now been corrected to the following which now works, for anyone else in the same situation:
<xsl:template match="/">
<xsl:apply-templates select="/LocalEvents/item"/>
</xsl:template>
<xsl:template match="item">
<div class="local_events">
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="Venue"/>
<xsl:apply-templates select="Times"/>
<xsl:apply-templates select="Dates"/>
<xsl:apply-templates select="DetailsURL"/>
</div><div style="height:1px;border-bottom:1px dotted #cfcfcf;"></div>
</xsl:template>
<xsl:template match="title">
<h2><a class="title" target="_blank" rel="nofollow" href="{../DetailsURL}"><xsl:value-of select="."/></a></h2>
</xsl:template>
<xsl:template match="Venue">
<span>Location: </span>
<xsl:value-of select="."/>
<br />
</xsl:template>
<xsl:template match="Times">
<span>Details: </span>
<xsl:value-of select="."/>
<br />
</xsl:template>
<xsl:template match="Dates">
<span>Dates: </span>
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="DetailsURL">
<a style="font-weight:normal;margin-left:0.5em;" target="_blank" rel="nofollow" href="{.}"><xsl:text>Full details...</xsl:text></a>
</xsl:template>
</xsl:stylesheet>
Other approuch. This stylesheet:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:preserve-space elements="Times"/>
<xsl:template match="text()"/>
<xsl:template match="item">
<div class="local_events">
<xsl:apply-templates/>
</div>
<div style="height:1px;border-bottom:1px dotted #cfcfcf;"></div>
</xsl:template>
<xsl:template match="title">
<h2>
<a class="title" target="_blank" rel="nofollow" href="{../DetailsURL}">
<xsl:value-of select="."/>
</a>
</h2>
</xsl:template>
<xsl:template match="Venue">
<span>Location: </span>
<xsl:value-of select="."/>
<br />
</xsl:template>
<xsl:template match="Times">
<span>Details: </span>
<xsl:value-of select="."/>
<br />
</xsl:template>
<xsl:template match="Dates">
<span>Dates: </span>
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="DetailsURL">
<a style="font-weight:normal;margin-left:0.5em;" target="_blank" rel="nofollow" href="{.}">
<xsl:text>Full details...</xsl:text>
</a>
</xsl:template>
</xsl:stylesheet>
Note: When doing a one to one transformation in the same hierarchy, it's enough to declare the rules for specific elements in input source and to overwrite the built-in rule for text node (output the string value) with an empty rule.

Resources