Following is some XSL that I'm editing. I had to add code to account for html tables and cannot figure out why the templates under [CITATIONS] are being applied, but those under [TABLES] are not. The code for [CITATIONS] was there and working before I started. The code for [TABLES] I stole from another part of the application and where it does work just fine. Does anything here stand out to anyone? Thanks in advance.
<!-- Common template for procedure sub-sections. -->
<xsl:template match="th:section" priority="1" mode="procedures">
<div id="tab{position()}">
<xsl:if test="count(*//th:figure) gt 0">
<hr/>
<div class="carrousel floatbox">
<!-- LOTS OF CODE HERE. -->
</div>
<hr/>
</xsl:if>
<xsl:next-match/>
</div>
</xsl:template>
<!-- [TABLES] Table templates not being applied. -->
<xsl:template match="th:table" mode="procedures">
<table border="1">
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="th:thead">
<thead>
<xsl:apply-templates/>
</thead>
</xsl:template>
<!-- [More table templates follow here to handle table body and footer. None are being applied.] -->
<!-- [CITATIONS] These templates are being applied. -->
<xsl:template match="th:section[#type = 'literature']" mode="procedures">
<ol class="litrefs">
<xsl:apply-templates mode="refs"/>
</ol>
</xsl:template>
<xsl:template match="th:litref" mode="refs">
<li>
<xsl:apply-templates mode="refs"/>
</li>
</xsl:template>
<!-- [More templates follow here to handle citations. No problems here.] -->
Related
I would like to know how it is possible to enumerate a table sequentially and to save this value into some kind of variable so this value can be selected in another template.
Each time the template table is called, the variable has to be incremented (the first value of the "counter" has to be 1).
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title>Tables.</title>
</head>
<body>
<xsl:apply-templates select="table"/>
<!-- apply more templates -->
</body>
</html>
</xsl:template>
<xsl:template match="table">
<center>
<b>Table **ENUMERATION OF THE TABLE** - </b><xsl:value-of select="title"/>
</center>
<br/>
</xsl:template>
<!-- more templates -->
Input (XML):
<table id="table1">
<title>Title.</title>
<br/>
</table>
<table id="table2">
<title>Title.</title>
<br/>
</table>
Output (HTML):
Table 1 - Title.
Table 2 - Title.
Your example is not a good one. If your input looks something like:
<root>
<table id="table1">
<title>Title 1</title>
</table>
<not-table/>
<table id="table2">
<title>Title 2</title>
</table>
<not-table/>
<table id="table3">
<title>Title 3</title>
</table>
</root>
then applying:
<xsl:template match="/root">
<xsl:copy>
<xsl:apply-templates select="table"/>
</xsl:copy>
</xsl:template>
<xsl:template match="table">
<center>
<b>Table <xsl:value-of select="position()"/> - </b>
<xsl:value-of select="title"/>
</center>
<br/>
</xsl:template>
will result in:
<root>
<center>
<b>Table 1 - </b>Title 1</center>
<br/>
<center>
<b>Table 2 - </b>Title 2</center>
<br/>
<center>
<b>Table 3 - </b>Title 3</center>
<br/>
</root>
I'm learning to use the mode attribute and must being doing something wrong. Apologies if this has been answered before but I'm not finding it here.
I want to process "title" elements separately depending on their context. For the main document, I want to add an "a" element inside of it:
<xsl:template match="title">
<div>
<xsl:value-of select="."/>
<a href="some_URL">some text
</a>
</div>
</xsl:template>
But elsewhere I'm creating result-documents where I just want the title:
<xsl:tamplate match="title" mode="print">
<div class="title">
<xsl:value-of select="."/>
</div>
</xsl:template>
In my main template match="/" I'm doing a for-each for each section, creating a result-document for each one:
<xsl:for-each select="/topic/body/bodydiv/section">
<xsl:result-document href="{$printoutfile}">
<html><head>some stuff</head><body>
<div class="section">
<xsl:apply-templates mode="print"/>
</div>
... more stuff...
</body</html>
</xsl:result-document>
</xsl:for-each>
Then I call everything else for the main document:
<html><head>stuff</head>
<body>
<div>
<xsl:apply-templates/>
</div>
</body>
</html>
The problem is this works for the result-document title but none of the rest of the result-document templates are used, since they don't have mode="print" on them. So the rest of the result-document all comes out as text.
Any idea what I need to do here? I'm obviously missing something basic.
thank you
Scott
You have not shown any of the other templates but if you expect the <xsl:apply-templates mode="print"/> to apply them then you need to have a mode="#all" on them. And if they do additional apply-templates then you need to use <xsl:apply-templates select="#current"/>. See http://www.w3.org/TR/xslt20/#modes for details.
I'm using the following xml information:
<section>
<...>
</section>
<section>
<templateId root="2.16.840.1.113883.10.20.22.2.10" />
<text>
<table id="Appointments">
<tr>
<td id="heading">Appointments</td>
</tr>
<tr>
<td id="content">No future appointments scheduled.</td>
</tr>
</table>
<br />
<table id="Referrals">
<tr>
<td id="heading">Referrals</td>
</tr>
<tr>
<td id="content">No referrals available.</td>
</tr>
</table>
<br />
</text>
<section>
<section>
<...>
</section>
There are multiple section nodes (with their own child nodes, including templateId) within the document. I'm having trouble with this one so I wanted to be specific in the xml information.
and in my xslt file I want to get one particular table out. I'm referencing it the following way (I'm trying to use templates and I'm new to XSL so please bear with me)
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="//section[templateId/#root='2.16.840.1.113883.10.20.22.2.17']/text/table[#id='Appointments']" />
</xsl: template>
<xsl:template match="section[templateId/#root='2.16.840.1.113883.10.20.22.2.17']/text/table[#id='Appointments']">
<div style="float: left; width: 50%;">
<span style="font-weight: bold;">
<xsl:value-of select="tr/td[#id='heading']"/>:
</span>
<br />
<xsl:call-template name="replace">
<xsl:with-param name="string" select="tr/td[#id='content']"/>
</xsl:call-template>
</div>
</xsl:template>
<xsl:template name="replace">
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="contains($string,'
')">
<xsl:value-of select="substring-before($string,'
')"/>
<br/>
<xsl:call-template name="replace">
<xsl:with-param name="string" select="substring-after($string,'
')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
In this particular xml example, the output should be:
Appointments:
No future appointments scheduled.
I'm thinking the match and select need some tweaking but not sure what part.
Also, if the template can be tweaked so that I could pass a parameter with the table/#id value so that I could reuse this one template for a couple of items,that would be even more beneficial (the output for referrals and appointments that are in this example would be the same).
Thanks for any help
This is your XML section root attribute (cut and paste from your XML):
root="2.16.840.1.113883.10.20.22.2.10"
This is your test XSL:
root='2.16.840.1.113883.10.20.22.2.17'
Of course they do not match, one ends with "10", the other with "17"
Changing the data to "17" and correcting the other errors in my comments yields:
<div style="float: left; width: 50%;"><span style="font-weight: bold;">Appointments:
</span><br>No future appointments scheduled.
</div
I am trying to achieve what is mentioned in the title, but having trouble, need help.
I am modifying the following templates
1. <xsl:template name="View_Default_RootTemplate" mode="RootTemplate" match="View" ddwrt:dvt_mode="root" ddwrt:ghost="hide">
2. <xsl:template match="View" mode="full" ddwrt:ghost="hide">
3. <xsl:template mode="Item" match="Row" ddwrt:ghost="hide">
Q-1 Should i be modifying any other templates?
Desired end result - To render a recursive view and each list item as <li>listitem...</li> surrounded by a top level <ul>
Q-2 when i change the <table> elements to <ul> and <tr> to <li> the final page is still rendered with tables which i don't see in the templates and the <ul> & <li> changes are inserted into some unknown <td>, the questions are
a. What is the right way to do this? and what template is applied in this case?
Here's a simple example that should take care of it for you. You really only need the following two templates:
<xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
<xsl:call-template name="Main"/>
</xsl:template>
<xsl:template name="Main">
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
<ul>
<xsl:for-each select="$Rows">
<li>
<xsl:value-of select="#Title"/>
</li>
</xsl:for-each>
</ul>
</xsl:template>
I have the following markup:
<ul id="slider">
<!-- slider item -->
<li>
...
</li>
<!-- end of slider item -->
</ul>
and I have defined the following itemStyle and GroupStyle xsl in header.xsl and itemStyle.xsl for displaying data from a SharePoint 2010 List:
<!-- in header.xsl -->
<xsl:template name="Slider" match="*[#GroupStyle='Slider']" mode="header">
<ul id="slider">
</ul>
</xsl:template>
<!-- in itemStyle.xsl -->
<xsl:template name="Slider" match="Row[#Style='Slider']" mode="itemstyle">
<xsl:variable name="SafeImageUrl">
<xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
<xsl:with-param name="UrlColumnName" select="#Picture"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="Title">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#Title" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="Details">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#Details" />
</xsl:call-template>
</xsl:variable>
<li>
<img src="{$SafeImageUrl}" alt="{$Title}" />
<section class="media-description">
<h2 class="slider-headline"><xsl:value-of disable-output-escaping="yes" select="$Title" /></h2>
<p><xsl:value-of disable-output-escaping="yes" select="$Details" /></p>
</section>
</li>
</xsl:template>
but the thing is, when applying the previous two templates, the <ul id="slider"></ul> appears isolated from all <li> items as below:
<ul id="slider"></ul>
<!-- a bunch of tables and td here.. -->
<ul style="width: 100%;" class="dfwp-column dfwp-list">
<li class="dfwp-item"></li>
<li>
<img alt="Must-see US exhibitions" src="">
<section class="media-description"><h2 class="slider-headline">Must-see US exhibitions</h2>
<p>(Blank)</p>
</section>
</li>
...
</ul>
all I want is to have <ul id="slider>" element to wrap those li's directly,
so how can i do that ?
Thanks
What's your input XML?
You'd do something like this:
<xsl:template name="Slider" match="*[#GroupStyle='Slider']" mode="header"><!-- Sure you want to match *? -->
<ul id="slider">
<!-- Match the input XML path to your rows from the context of the matched element above -->
<xsl:apply-templates select="Row[#Style='Slider']" mode="itemstyle" />
</ul>
</xsl:template>
<xsl:template name="Slider" match="Row[#Style='Slider']" mode="itemstyle">
<li>..</li>
</xsl:template>
Can't figure out why you are using "mode"s either.
problem solved, thanks to #James Love,
and here are the steps:
make a copy of ContentQueryMain.xsl, as the following article says
after having a copy of ContentQueryMain.xsl, edit it and look for OutTemplate.Body
then you can place your wrapper in the following variables (but they have to be escaped)
<xsl:template name="OuterTemplate.Body">
<xsl:variable name="BeginColumn1" select="string('<ul id="slider" class="dfwp-column dfwp-list" style="width:')" />
<!-- ^------------------^ -->
<xsl:variable name="BeginColumn2" select="string('%" >')" />
<xsl:variable name="BeginColumn" select="concat($BeginColumn1, $cbq_columnwidth, $BeginColumn2)" />
<xsl:variable name="EndColumn" select="string('</ul>')" />
<!-- ^---------^ -->
stupid workaround, but its working :S