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>
Related
I'm writing a XSLT script and there is a section named footnotes, my script is catching all elements other than footnotes. I'm using XSL2.0 and Below is my XML
<?xml version="1.0" encoding="utf-8"?>
<chapter num="D" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:acknowledgement="file://acknowledgement.xsd" xmlns:admission="file://admission.xsd" xmlns:affidavit="file://affidavit.xsd" xmlns:agreement="file://agreement.xsd" xmlns:appeal="file://appeal.xsd" xmlns:appearance="file://appearance.xsd" xmlns:application="file://application.xsd" xmlns:assent="file://assent.xsd" xmlns:authorisation="file://authorisation.xsd" xmlns:award="file://award.xsd" xmlns:brief="file://brief.xsd" xmlns:caveat="file://caveat.xsd" xmlns:certificate="file://certificate.xsd" xmlns:checklist="file://checklist.xsd" xmlns:claim="file://claim.xsd" xmlns:clause="file://clause.xsd" xmlns:comparisontable="file://comparisontable.xsd" xmlns:conditionsofcontract="file://conditionsofcontract.xsd" xmlns:declaration="file://declaration.xsd" xmlns:defaultjudgment="file://defaultjudgment.xsd" xmlns:defence="file://defence.xsd" xmlns:demand="file://demand.xsd" xmlns:flowchart="file://flowchart.xsd" xmlns:form="file://form.xsd" xmlns:guarantee="file://guarantee.xsd" xmlns:instruction="file://instruction.xsd" xmlns:judgment="file://judgment.xsd" xmlns:letter="file://letter.xsd" xmlns:minutes="file://minutes.xsd" xmlns:notice="file://notice.xsd" xmlns:oath="file://oath.xsd" xmlns:order="file://order.xsd" xmlns:patent="file://patent.xsd" xmlns:petition="file://petition.xsd" xmlns:powerofattorney="file://powerofattorney.xsd" xmlns:praecipe="file://praecipe.xsd" xmlns:questionnaire="file://questionnaire.xsd" xmlns:recognisance="file://recognisance.xsd" xmlns:release="file://release.xsd" xmlns:renunciation="file://renunciation.xsd" xmlns:reply="file://reply.xsd" xmlns:report="file://report.xsd" xmlns:request="file://request.xsd" xmlns:schedule="file://schedule.xsd" xmlns:statementofclaim="file://statementofclaim.xsd" xmlns:subpoena="file://subpoena.xsd" xmlns:summons="file://summons.xsd" xmlns:undertaking="file://undertaking.xsd" xmlns:warrant="file://warrant.xsd" xmlns:writ="file://writ.xsd" xmlns:book="file://book.xsd" xmlns:forms="file://forms.xsd" xmlns:misc="file://misc.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:htm="http://www.w3.org/TR/html5/">
<htm:p align="center">
<htm:b>Bold Content</htm:b>
<footnote num="1">
<para>
Footnote content.
</para>
</footnote>
</htm:p>
</chapter>
And below is my XSLT.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ntw="Number2Word.uri" xmlns:altova="http://www.altova.com/xslt-extensions" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:acknowledgement="file://acknowledgement.xsd" xmlns:admission="file://admission.xsd" xmlns:affidavit="file://affidavit.xsd" xmlns:agreement="file://agreement.xsd" xmlns:appeal="file://appeal.xsd" xmlns:appearance="file://appearance.xsd" xmlns:application="file://application.xsd" xmlns:assent="file://assent.xsd" xmlns:authorisation="file://authorisation.xsd" xmlns:award="file://award.xsd" xmlns:brief="file://brief.xsd" xmlns:caveat="file://caveat.xsd" xmlns:certificate="file://certificate.xsd" xmlns:checklist="file://checklist.xsd" xmlns:claim="file://claim.xsd" xmlns:clause="file://clause.xsd" xmlns:comparisontable="file://comparisontable.xsd" xmlns:conditionsofcontract="file://conditionsofcontract.xsd" xmlns:declaration="file://declaration.xsd" xmlns:defaultjudgment="file://defaultjudgment.xsd" xmlns:defence="file://defence.xsd" xmlns:demand="file://demand.xsd" xmlns:flowchart="file://flowchart.xsd" xmlns:form="file://form.xsd" xmlns:guarantee="file://guarantee.xsd" xmlns:instruction="file://instruction.xsd" xmlns:judgment="file://judgment.xsd" xmlns:letter="file://letter.xsd" xmlns:minutes="file://minutes.xsd" xmlns:notice="file://notice.xsd" xmlns:oath="file://oath.xsd" xmlns:order="file://order.xsd" xmlns:patent="file://patent.xsd" xmlns:petition="file://petition.xsd" xmlns:powerofattorney="file://powerofattorney.xsd" xmlns:praecipe="file://praecipe.xsd" xmlns:questionnaire="file://questionnaire.xsd" xmlns:recognisance="file://recognisance.xsd" xmlns:release="file://release.xsd" xmlns:renunciation="file://renunciation.xsd" xmlns:reply="file://reply.xsd" xmlns:report="file://report.xsd" xmlns:request="file://request.xsd" xmlns:schedule="file://schedule.xsd" xmlns:statementofclaim="file://statementofclaim.xsd" xmlns:subpoena="file://subpoena.xsd" xmlns:summons="file://summons.xsd" xmlns:undertaking="file://undertaking.xsd" xmlns:warrant="file://warrant.xsd" xmlns:writ="file://writ.xsd" xmlns:book="file://book.xsd" xmlns:forms="file://forms.xsd" xmlns:misc="file://misc.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:htm="http://www.w3.org/TR/html5/" xpath-default-namespace="http://foo.bar.com/ns" exclude-result-prefixes="#all">
<xsl:output method="html"/>
<xsl:strip-space elements="*"/>
<!--<xsl:preserve-space elements="para"/>-->
<xsl:variable name="nums" as="element()+">
<ntw:nums num="1" word="first"/>
<ntw:nums num="2" word="second"/>
<ntw:nums num="3" word="third"/>
<ntw:nums num="4" word="forth"/>
<ntw:nums num="5" word="fifth"/>
<ntw:nums num="6" word="sixth"/>
<ntw:nums num="7" word="seventh"/>
<ntw:nums num="8" word="eighth"/>
<ntw:nums num="9" word="nighth"/>
<ntw:nums num="10" word="tenth"/>
</xsl:variable>
<xsl:template match="/">
<xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE html>]]></xsl:text>
<html>
<head>
<xsl:text disable-output-escaping="yes"><![CDATA[</meta>]]></xsl:text>
<title>
<xsl:value-of select="chapter/title/text()"/>
</title>
<link rel="stylesheet" href="C:\Users\u0138039\Desktop\Proview\MY\2016\CCA3ED\XML\XSLT\main.css" type="text/css"/>
<xsl:text disable-output-escaping="yes"><![CDATA[</link>]]></xsl:text>
</head>
<body>
<section class="tr_chapter">
<xsl:apply-templates/>
</section>
<xsl:if test="//footnote">
<section class="tr_footnotes">
<xsl:text disable-output-escaping="yes"><![CDATA[<hr />]]></xsl:text>
<xsl:apply-templates select="//page | //footnote" mode="footnote"/>
</section>
</xsl:if>
</body>
</html>
</xsl:template>
<xsl:template match="chapter">
<xsl:apply-templates select="descendant::title[1]/page" mode="first"/>
<div class="chapter">
<xsl:variable name="num_S">
<xsl:value-of select="."/>
</xsl:variable>
<a name="CLIHK_CH_{$num_S}"/>
<div class="chapter-title">
<span class="chapter-num">
<xsl:value-of select="normalize-space(concat('Chapter ',format-number(./#num,'0')))"/>
</span>
<xsl:text disable-output-escaping="yes"><![CDATA[<br /><br />]]></xsl:text>
<xsl:apply-templates select="title/node() except descendant-or-self::page"/>
<xsl:text disable-output-escaping="yes"><![CDATA[<br /><br />]]></xsl:text>
<xsl:apply-templates select="chapter-meta"/>
</div>
<xsl:apply-templates select="child::node()[not(self::title|self::chapter-meta)]"/>
</div>
</xsl:template>
<xsl:template match="htm:b">
<span class="font-style-bold">
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="htm:p">
<xsl:apply-templates select="./node()[1][self::page]" mode="first"/>
<div>
<xsl:choose>
<xsl:when test="./#align">
<xsl:attribute name="class"><xsl:text>para align-</xsl:text><xsl:value-of select="./#align"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="class"><xsl:text>para</xsl:text></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="footnote">
<xsl:variable name="cnt" select="count(preceding::footnote)+1"/>
<xsl:variable name="varHeaderNote" select='concat("f",$cnt)'/>
<xsl:variable name="varFootNote" select='concat("#ftn.",$cnt)'/>
<sup>
<a name="{$varHeaderNote}" href="{$varFootNote}" class="tr_ftn">
<xsl:value-of select="#num"/>
</a>
</sup>
</xsl:template>
<xsl:template match="footnote" mode="footnote">
<xsl:variable name="cnt" select="count(preceding::footnote)+1"/>
<div class="tr_footnote">
<div class="footnote">
<sup>
<a>
<xsl:attribute name="name"><xsl:text>ftn.</xsl:text><xsl:value-of select="$cnt"/></xsl:attribute>
<xsl:attribute name="href"><xsl:text>#f</xsl:text><xsl:value-of select="$cnt"/></xsl:attribute>
<xsl:attribute name="class"><xsl:text>tr_ftn</xsl:text></xsl:attribute>
<xsl:value-of select="#num"/>
</a>
</sup>
<xsl:apply-templates/>
</div>
</div>
</xsl:template>
</xsl:stylesheet>
My current output is as below
<!DOCTYPE html><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
<title></title>
<link rel="stylesheet" href="C:\Users\u0138039\Desktop\Proview\MY\2016\CCA3ED\XML\XSLT\main.css" type="text/css"></link>
</head>
<body>
<section class="tr_chapter">
<div class="para align-center"><span class="font-style-bold">Bold Content</span>
Footnote content.
</div>
</section>
</body>
</html>
But my expected output is
<!DOCTYPE html><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
<title></title>
<link rel="stylesheet" href="C:\Users\u0138039\Desktop\Proview\MY\2016\CCA3ED\XML\XSLT\main.css" type="text/css"></link>
</head>
<body>
<section class="tr_chapter">
<div class="para align-center"><span class="font-style-bold">Bold Content</span><sup>
<a name="f1" href="#ftn.1" class="tr_ftn">1</a>
</sup>
</div>
</section>
<section class="tr_footnotes"><hr/>
<div class="tr_footnote">
<div class="footnote">
<sup>
<a name="ftn.1" href="#f1" class="tr_ftn">1</a>
</sup>
<div class="para">Footnote content.
</div>
</div>
</div></section>
</body>
</html>
Here is a working demo
please let me know where Am I going wrong and how can I fix this.
Thanks
Your stylesheet declares:
xpath-default-namespace="http://foo.bar.com/ns"
The footnote in your XML is in no namespace, therefore the test in:
<xsl:if test="//footnote">
returns false.
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'm looking to get some XSLT (for Umbraco CMS) coded properly and I'm getting kind of stumped. What I'm trying to do is:
Start from a certain node, put each child node into a div; for every 3 children, wrap in a parent div.
Instead of my mess of for-each,choose and when statements, I have tried implementing a apply-template structure but I just can't seem to get the hang of it; so here's my mess of XSLT right now (I'm sure this is bad practice & terrible for performance, but I really don't know what to do at the moment):
<div class="row four">
<h2>Smart Phones see all smart phones →</h2>
<div class="row three"> <!-- This div should be created again for every 3 divs -->
<xsl:for-each select="umbraco.library:GetXmlNodeById('1063')/descendant::*[#isDoc and string(showInMainNavigation) = '1']">
<xsl:choose>
<xsl:when test="position() < 3">
<div class="col">
<a href="{umbraco.library:NiceUrl(./#id)}">
<img class="phonePreviewImg" src="{./previewImage}" style="max-width:117px; max-height:179px;" />
<h4 class="phoneTitle"><xsl:value-of select="./#nodeName" />/h4>
<p class="phonePrice">$<xsl:value-of select="./price" /></p
</a>
</div>
</xsl:when>
<xsl:when test="position() = 3"> <!-- set this div to include class of `omega` -->
<div class="col omega">
<a href="{umbraco.library:NiceUrl(./#id)}">
<img class="phonePreviewImg" src="{./previewImage}" style="max-width:117px; max-height:179px;" />
<h4 class="phoneTitle"><xsl:value-of select="./#nodeName" />/h4>
<p class="phonePrice">$<xsl:value-of select="./price" /></p
</a>
</div>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</div> <!-- End Row Three -->
</div> <!-- End Row Four -->
Obviously this code does not produce the "wrap every three". Can anyone shed some light on what I need to do to accomplish this?
UPDATE - improved the answer
I cannot think of an elegant solution using templates, but this clunky one with a loop works:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="render">
<xsl:param name="node"/>
<xsl:param name="last"/>
<div>
<xsl:if test="$last">
<xsl:attribute name="class">
<xsl:text>omega</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:value-of select="$node"/>
</div>
</xsl:template>
<xsl:template match="/*">
<root>
<xsl:variable name="nodes" select="*[not(#skip)]"/>
<xsl:for-each select="$nodes">
<xsl:if test="(position() mod 3)=1">
<xsl:variable name="position" select="position()"/>
<div>
<xsl:call-template name="render">
<xsl:with-param name="node" select="."/>
<xsl:with-param name="last" select="false()"/>
</xsl:call-template>
<xsl:if test="$nodes[$position+1]">
<xsl:call-template name="render">
<xsl:with-param name="node" select="$nodes[$position+1]"/>
<xsl:with-param name="last" select="false()"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="$nodes[$position+2]">
<xsl:call-template name="render">
<xsl:with-param name="node" select="$nodes[$position+2]"/>
<xsl:with-param name="last" select="true()"/>
</xsl:call-template>
</xsl:if>
</div>
</xsl:if>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>
applied to:
<root>
<node>1</node>
<node skip="1">to be skipped</node>
<node>2</node>
<node>3</node>
<node skip="1">to be skipped</node>
<node skip="1">to be skipped</node>
<node>4</node>
<node skip="1">to be skipped</node>
<node>5</node>
<node>6</node>
<node>7</node>
<node skip="1">to be skipped</node>
</root>
produces:
<root>
<div>
<div>1</div>
<div>2</div>
<div class="omega">3</div>
</div>
<div>
<div>4</div>
<div>5</div>
<div class="omega">6</div>
</div>
<div>
<div>7</div>
</div>
</root>
You need to replace the select used to set the $nodes variable the XPath selecting the nodes you want, and the render template with the code needed to generate the result you need for each node.
As simple and short as this:
<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="num[position() mod 3 = 1]">
<div>
<xsl:apply-templates mode="inGroup"
select=".|following-sibling::*[not(position() >2)]"/>
</div>
</xsl:template>
<xsl:template match="num" mode="inGroup">
<p><xsl:apply-templates mode="inGroup"/></p>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
When this transformation is applied on the following XML document:
<nums>
<num>01</num>
<num>02</num>
<num>03</num>
<num>04</num>
<num>05</num>
<num>06</num>
<num>07</num>
<num>08</num>
<num>09</num>
<num>10</num>
</nums>
the wanted, correct result is produced:
<div>
<p>01</p>
<p>02</p>
<p>03</p>
</div>
<div>
<p>04</p>
<p>05</p>
<p>06</p>
</div>
<div>
<p>07</p>
<p>08</p>
<p>09</p>
</div>
<div>
<p>10</p>
</div>
Here's an elegant solution using templates.
When this XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:param name="pNumInGroup" select="3" />
<xsl:template match="/*">
<html>
<xsl:apply-templates select="*[position() mod $pNumInGroup = 1]" />
</html>
</xsl:template>
<xsl:template match="node">
<div>
<xsl:for-each
select=".|following-sibling::*[not(position() > $pNumInGroup - 1)]">
<div>
<xsl:apply-templates />
</div>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
...is applied to the sample XML provided by #MiMo:
<root>
<node>1</node>
<node>2</node>
<node>3</node>
<node>4</node>
<node>5</node>
<node>6</node>
<node>7</node>
</root>
...the correct result is produced:
<html>
<div>
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
<div>
<div>7</div>
</div>
</html>
If the parameter value is changed to 5:
<xsl:param name="pNumInGroup" select="5" />
...the correct result is still produced:
<html>
<div>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
<div>
<div>6</div>
<div>7</div>
</div>
</html>
Explanation:
We define a pNumInGroup parameter at the top of the document (with a default value of 3). This is useful, as it allows the XSLT to be used more flexibly (i.e., if you need a different number of <div> elements per group, simply pass them as a parameter).
The first template matches the root node, recreates it, and tells the XSLT processor to apply templates to the first element of each grouping (here's a refresher in modular arithmetic in case you need it).
The second template matches the <node> elements that are selected by the previous template. For each, a new <div> element is created and populated with the remaining items appropriate to that wrapped group.
NOTE: I generally stay away from <xsl:for-each> unless I really need it; in the case of the last template, I don't really need it (I could just as easily have specified the wrapping/secondary <div> logic with another template). However, for the sake of "crispness" and not over-templating the XSLT, I chose this route.
This is my first time that I am using Content Query Web part and xslt. I have to display the last 5 posts from a blog in the following fashion (please look at the image below):
The table contains two columns. In the left column I would like to display the last post and in the right column I would like to display the rest of the posts from a particual blog.
Edit 1
The source is just an OOTB Blog Site and I have added a few posts in it. I would like to display these posts in an html table which contains two columns. In the left column I would like to display the last post entered in the blog and in the right column I would like to loop through other posts. The user must specify how many posts he/she would like to see in the CQWP.
Edit 2
This is the xslt that I have created so far. The only think is that the table is being repeated multiple times, which I don't want that. There should be only one table. If you look in the xslt code I have manually entered some text, like Test1, test 2... In their place I would like to display the rest of the blog posts.
<xsl:template name="Post" match="Row[#Style='Post']" mode="itemstyle">
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="DisplayTitle">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="#Title"/>
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<div>
<table width="100%" cellpadding="2" cellspacing="2" border="1">
<tr>
<td colspan="2" valign="top">
<xsl:value-of select="#Author"/></td>
<td rowspan="2" valign="top" width="30%">
<div>
<b>Previous blog posts:</b>
</div>
<div>
<ul style="margin-left:-2px;">
<li>Test 1</li>
<li>Test 2</li>
<li>Test 3</li>
<li>Test 4</li>
</ul>
</div>
</td>
</tr>
<tr>
<td width="15%" valign="top">
image</td>
<td valign="top">
<div>
<xsl:value-of select="#Title"/>
</div>
<div class="custom_description">
<xsl:value-of select="#Body" disable-output-escaping="yes" />
</div>
<p>
<xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
<a href="{$SafeLinkUrl}">
<xsl:if test="$ItemsHaveStreams = 'True'">
<xsl:attribute name="onclick">
<xsl:value-of select="#OnClickForWebRendering"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$ItemsHaveStreams != 'True' and #OpenInNewWindow = 'True'">
<xsl:attribute name="onclick">
<xsl:value-of disable-output-escaping="yes" select="$OnClickTargetAttribute"/>
</xsl:attribute>
</xsl:if>
<br />
<b>Read More ></b>
</a>
</p>
</td>
</tr>
</table>
</div>
</xsl:template>
Edit 3
<root>
<Posts>
<Post ID="1">
<Title>this post 1</Title>
<Body>The comment comes here</Body>
</Post>
<Post ID="2">
<Title>this post 2</Title>
<Body>The comment comes here</Body>
</Post>
<Post ID="3">
<Title>this post 3</Title>
<Body>The comment comes here</Body>
</Post>
<Post ID="4">
<Title>this post 4</Title>
<Body>The comment comes here</Body>
</Post>
<Post ID="5">
<Title>this post 5</Title>
<Body>The comment comes here</Body>
</Post>
</Posts>
</root>
Thank you
First let me caveat emptor: I know nothing about SharePoint, and I do not have an installation of SharePoint installed. There is a StackExchange website which specialised in SharePoint questions, and this site may serve you better than SO. See https://sharepoint.stackexchange.com/questions/22465/recreating-the-blog-template
You should also take a look at http://www.glynblogs.com/2011/04/overriding-the-presentation-of-an-xslt-list-view-web-part.html .
UPDATE
This XSLT 1.0 style-sheet, for an MS XSLT processor...
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="xsl msxsl">
<xsl:output method="html" doctype-system="" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*" />
<xsl:variable name="empty-main">
<empty-main>No content yet.</empty-main>
</xsl:variable>
<xsl:variable name="empty-sub">
<empty-main>No older content yet.</empty-main>
</xsl:variable>
<xsl:template match="/*">
<html>
<head>
<title>Blog</title>
<style type="text/css">
table {
width: 100%;
border: 1px solid #000;
}
td.main-col, td.subsiduary-col {
vertical-align:text-top;
}
td.main-col {
width: 75%
}
td.subsiduary-col {
width: 25%
}
</style>
</head>
<body>
<table border="1">
<tr>
<xsl:variable name="count-posts" select="count(msxsl:node-set(Posts/Post))" />
<td class="main-col">
<xsl:apply-templates select="
(Posts/Post[last()] | msxsl:node-set($empty-main))[1]" />
</td>
<td class="subsiduary-col">
<xsl:apply-templates select="
Posts/Post[position() > last() - 5 and position() < last()] |
msxsl:node-set($empty-sub)[$count-posts < 2]" />
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="Post">
<xsl:apply-templates select="Title" />
<p><xsl:copy-of select="Body/node()" /></p>
</xsl:template>
<xsl:template match="Post[last()]/Title" priority="2">
<h1><xsl:value-of select="." /></h1>
</xsl:template>
<xsl:template match="Post/Title">
<h2><xsl:value-of select="." /></h2>
</xsl:template>
<xsl:template match="empty-main|empty-sub" priority="2">
<p><xsl:value-of select="." /></p>
</xsl:template>
</xsl:stylesheet>
...will transform this input...
<root>
<Posts>
<Post ID="1">
<Title>this post 1</Title>
<Body>The comment comes here</Body>
</Post>
<Post ID="2">
<Title>this post 2</Title>
<Body>The comment comes here</Body>
</Post>
<Post ID="3">
<Title>this post 3</Title>
<Body>The comment comes here</Body>
</Post>
<Post ID="4">
<Title>this post 4</Title>
<Body>The comment comes here</Body>
</Post>
<Post ID="5">
<Title>this post 5</Title>
<Body>The comment comes here</Body>
</Post>
</Posts>
</root>
..into this output...
<!DOCTYPE html SYSTEM "">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Blog</title>
<style type="text/css">
table {
width: 100%;
border: 1px solid #000;
}
td.main-col, td.subsiduary-col {
vertical-align:text-top;
}
td.main-col {
width: 75%
}
td.subsiduary-col {
width: 25%
}
</style>
</head>
<body>
<table border="1">
<tr>
<td class="main-col">
<h1>this post 5</h1>
<p>The comment comes here</p>
</td>
<td class="subsiduary-col">
<h2>this post 1</h2>
<p>The comment comes here</p>
<h2>this post 2</h2>
<p>The comment comes here</p>
<h2>this post 3</h2>
<p>The comment comes here</p>
<h2>this post 4</h2>
<p>The comment comes here</p>
</td>
</tr>
</table>
</body>
</html>
For a visual of how this renders in a browser, paste the html output into http://htmledit.squarefree.com/ .
Displays the first or the last item depending on Sorting selected in the panel tool of the web part.
<xsl:if test="count(preceding-sibling::*)=0">
Example
<xsl:template name="DisplayPosts" match="Row[#Style='DisplayPosts']" mode="itemstyle">
<table width="100%" border="1">
<tr>
<td width="70%">
<xsl:if test="count(preceding-sibling::*)=0">
<xsl:value-of select="#Title" />
</xsl:if>
</td>
<td width="30%">
<xsl:if test="count(preceding-sibling::*)>0">
<xsl:value-of select="#Title" />
</xsl:if>
</td>
</tr>
</table>
</xsl:template>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" />
<xsl:template match="/">
<html>
<body>
<span>
<div style="background-color:#000066;color:#EEEEEE;padding:7px">
<a name="top" style="padding-left:10px;font-size:28pt">Alerting Variables</a>
</div>
</span>
<div style="display:block;padding-left:50px;padding-bottom:10px" class="hbuttons">
LDMS Alerts
LDSM Alerts
Why?
Examples
Resources
</div>
<div style="clear: left;"></div>
<!-- This is the Table of Contents-->
<div style="padding:5px">
<div style="padding:5px;margin-top:10pt;margin-bottom:10pt;font-weight:bold;font-size:20px">Table of Contents -
<a style="position:absolute;margin-left:40px" href="PrintPages/PrintAll.html">
<img border="0" src="images/PrintButton.png" />
</a></div>
<div style="font-family:Arial;font-weight:bold;margin-left:30px;font-size:10pt">
<xsl:if test="contains(identifiers/sectionname/alert/#name, 'Agent Watcher')">
Agent Watcher
<a style="position:absolute;margin-left:40px" href="PrintPages/PrintAW.html">
<img border="0" src="images/PrintButton.png" />
</a>
</xsl:if>
<ol style="margin-top:5">
<xsl:for-each select="identifiers/sectionname/alert">
<xsl:if test="contains(#name, 'Agent Watcher')">
<li style="margin-left:10pt;font-size:8pt">
<a>
<xsl:attribute name="href">#
<xsl:value-of select="#name" /></xsl:attribute>
<xsl:value-of select="#name" />
</a>
</li>
</xsl:if>
</xsl:for-each>
</ol>
</div>
<div style="font-family:Arial;font-weight:bold;margin-left:30px;font-size:10pt">
Intel vPro
<a style="position:absolute;margin-left:40px" href="PrintPages/PrintvPro.html">
<img border="0" src="images/PrintButton.png" />
</a>
<ol style="margin-top:5">
<xsl:for-each select="identifiers/SectionName/alert">
<xsl:if test="contains(#name, 'Intel vPro')">
<li style="margin-left:10pt;font-size:8pt">
<a>
<xsl:attribute name="href">#
<xsl:value-of select="#name" /></xsl:attribute>
<xsl:value-of select="#name" />
</a>
</li>
</xsl:if>
</xsl:for-each>
</ol>
</div>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Above is my code sample.
The first xsl:if statement always fails and never shows the Agent Watcher text or print me button. Even if the section is filled out in the XML. If the section is there, the first xsl:if statement fails, but the second one, contained in the xsl:for-each shows the content. How do I get this to work.
I want to have it encompassing so that if the XML has content in the section it will put it up but if not it wont be empty content with a header or vice versa. Attaching sample XML to process.
<identifiers>
<sectionname>
<alert name="Agent Watcher Service Startup"></alert>
<alert name="Agent Watcher Service Not Started"></alert>
<alert name="Agent Watcher Service Uninstalled"></alert>
<alert name="Agent Watcher File Deleted"></alert>
</sectionname>
<sectionname>
<alert name="Intel vPro agentless discovery failure"></alert>
<alert name="Intel vPro System Defense Remediation Alert"></alert>
<alert name="Intel vPro Enhanced System Defense Remediation Alert"></alert>
<alert name="Intel vPro Enhanced System Defense Alert"></alert>
</sectionname>
</identifiers>
Blockquote
I have a few other suggestions but you need to post the entire (relevant) XSLT before I can go on. At least the enclosing template is necessary.
EDIT: Here is my proposal for your stylesheet:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tmp="http://tempuri.org"
exclude-result-prefixes="tmp"
>
<tmp:config>
<tmp:alert label="Agent Watcher" link="PrintPages/PrintAW.html" />
<tmp:alert label="Intel vPro" link="PrintPages/PrintvPro.html" />
</tmp:config>
<xsl:variable name="everyAlert" select="
/identifiers/sectionname/alert
" />
<xsl:template match="/">
<html>
<body>
<!-- 8< snip -->
<div style="...">
<div style="...">
<xsl:text>Table of Contents - </xsl:text>
<a style="..." href="PrintPages/PrintAll.html">
<img border="0" src="images/PrintButton.png" />
</a>
</div>
<xsl:for-each select="document('')/*/tmp:config/tmp:alert">
<xsl:call-template name="section" />
</xsl:for-each>
</div>
</body>
</html>
</xsl:template>
<xsl:template name="section">
<xsl:variable name="this" select="." />
<xsl:variable name="alerts" select="
$everyAlert[contains(#name, $this/#label)]
" />
<xsl:if test="$alerts">
<div style="...">
<a href="#{translate($this/#label, ' ', '_')}">
<xsl:value-of select="$this/#label" />
</a>
<a style="..." href="{$this/#link}">
<img border="0" src="images/PrintButton.png" />
</a>
<ol style="...">
<xsl:for-each select="$alerts">
<li style="...">
<xsl:value-of select="#name" />
</li>
</xsl:for-each>
</ol>
</div>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Key features:
efficient code reuse through a named template
printed sections are easily configurable
uses <xsl:text> elements to avoid unwanted whitespace in the output while retaining freedom to format the XSLT code properly
uses attribute literal notation (the curly braces {}) instead of verbose <xsl:attribute> elements
uses a temporary namespace to allow storing config data in the stylesheet itself
uses an <xsl:for-each> loop and the document() function to retrieve and work with that config data
the for-each makes use of the context to transport the current #label and #link so no <xsl:param> is necessary (the <xsl:template name="section"> runs in tmp:config/tmp:alert context, not in sectionname/alert context!)
uses a global variable ($everyAlert) to store all nodes for later use