I'm having some issue with my xslt code and I was Wondering if someone could take a look. I think the problem is with the date formatting but i'm not sure.
I need to format a datetime into a day and month.
this is my code:
<xsl:stylesheet
version="1.0"
exclude-result-prefixes="x d xsl msxsl cmswrt"
xmlns:x="http://www.w3.org/2001/XMLSchema"
xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
<xsl:template name="NewsAndEvents" match="Row[#Style='NewsAndEvents']" mode="itemstyle">
<xsl:variable name="SafeImageUrl">
<xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
<xsl:with-param name="UrlColumnName" select="'ImageUrl'"/>
</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>
<xsl:variable name="ArticleDate">
<xsl:value-of select="#SongDate"/>
</xsl:variable>
<xsl:if test="string-length($SafeImageUrl) != 0">
<div class="event-contain">
<div class="event-img pull-right">
<div class="white-box">
<h1><xsl:value-of select="ddwrt:FormatDate(string($ArticleDate),1037, 'MMMM')"/></h1>
<h2><xsl:value-of select="ddwrt:FormatDate(string($ArticleDate),1037, 'd')"/></h2>
</div>
<img src="{$SafeImageUrl}" title="{#ImageUrlAltText}">
<xsl:if test="$ImageWidth != ''">
<xsl:attribute name="width">
<xsl:value-of select="$ImageWidth" />
</xsl:attribute>
</xsl:if>
<xsl:if test="$ImageHeight != ''">
<xsl:attribute name="height">
<xsl:value-of select="$ImageHeight" />
</xsl:attribute>
</xsl:if>
</img>
</div>
<div class="text-sec pull-right">
<header>
<hgroup>
<h3 class="ttl md fnt-bld blue"> <xsl:value-of select="$DisplayTitle"/> </h3>
<h4 class="ttl sm fnt-bld blue-mob"> <xsl:value-of select="#SongDescription"/> </h4>
</hgroup>
</header>
<div class="row dynamic-text-contain pull-right">
<p class="ttl xs">
<span class="display-on-mob"><xsl:value-of select="#NewsDescription" /></span>
</p>
</div>
<div class="row">
<div class="display-all read-more-eruim no-mob">
<div class="display-more open-link">
<a>
<i class="icon-icons2-50"></i>
<p>
<span class="btn-text">Show All</span>
<i class="icon-icons2-10 left-arrow" id="arrow"></i>
</p>
</a>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="line"></div>
</div>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Tnx For the Help Yotam.
I Have a Solution If any one ever has this problem:
the thing is that:
<xsl:value-of select="ddwrt:FormatDate(string($ArticleDate),1037, 'd')"/>
is the wrong syntax and should be :
<xsl:value-of select="ddwrt:FormatDateTime(string($ArticleDate),1037, 'd')"/>
Now, another thing is that it returns the value as: dd/mm/yyyy and I only wanted the day so I used a sub string function like so:
<xsl:value-of select="substring-before(ddwrt:FormatDateTime(string($ArticleDate),1037, 'd'),'/')"/>
This Solved me this issue :)
Related
I am absolutely a beginner to XSLT. I am using xslt to convert data to a HTML table. I need help to avoid some duplicates.
I have tried several fixes but non of then worked.
This is my XML file.
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Identifikasjon>
<Internref>12909524760066</Internref>
</Identifikasjon>
<NavnAdresse>
<Status>0</Status>
<StatusDato>2009-10-27</StatusDato>
<Fodselsdato>1901-01-01</Fodselsdato>
<Navn>DEMO PERSON</Navn>
<Adresse>TESTEGATA 76</Adresse>
<Postnr>4950</Postnr>
<Poststed>RISØR</Poststed>
<Kommune>RISØR</Kommune>
<Fylke>AUST-AGDER</Fylke>
<Alder>118</Alder>
<Kjonn>MANN</Kjonn>
</NavnAdresse>
<BetaDetaljer>
<RegistrertDato>2001-12-10</RegistrertDato>
<BetaGruppeKode>NE</BetaGruppeKode>
<BetaGruppeTekst>Negative</BetaGruppeTekst>
<BetaType>UL</BetaType>
<BetaTekst>UTLEGG</BetaTekst>
<BetaBelop>2111</BetaBelop>
<KildeKode>LØSØ</KildeKode>
<KildeTekst>LØSØREREGISTERET</KildeTekst>
<KildeReferansenr>12345</KildeReferansenr>
<Kreditor>TESTKREDITOREN</Kreditor>
</BetaDetaljer>
<Ligning>
<SkatteAr>2018</SkatteAr>
<Formue>1111111</Formue>
<EndringFormue>117.39</EndringFormue>
<Inntekt>511111</Inntekt>
<EndringInntekt>0.0</EndringInntekt>
<Skatt>111111</Skatt>
<SkatteKlasse>1E</SkatteKlasse>
<Kommunenr>301</Kommunenr>
<KommuneNavn>OSLO</KommuneNavn>
<BruttoInntekt>0</BruttoInntekt>
<Gjeldsgrad1>0.0</Gjeldsgrad1>
<Gjeldsgrad2>0.0</Gjeldsgrad2>
</Ligning>
<Ligning>
<SkatteAr>2017</SkatteAr>
<Formue>511111</Formue>
<EndringFormue>0.0</EndringFormue>
<Inntekt>511111</Inntekt>
<EndringInntekt>0.0</EndringInntekt>
<Skatt>111111</Skatt>
<SkatteKlasse>1E</SkatteKlasse>
<Kommunenr>1534</Kommunenr>
<KommuneNavn>HARAM</KommuneNavn>
<BruttoInntekt>0</BruttoInntekt>
<Gjeldsgrad1>0.0</Gjeldsgrad1>
<Gjeldsgrad2>0.0</Gjeldsgrad2>
</Ligning>
<Ligning>
<SkatteAr>2016</SkatteAr>
<Formue>511111</Formue>
<EndringFormue>0.0</EndringFormue>
<Inntekt>511111</Inntekt>
<EndringInntekt>0.0</EndringInntekt>
<Skatt>111111</Skatt>
<SkatteKlasse>1E</SkatteKlasse>
<Kommunenr>1534</Kommunenr>
<KommuneNavn>HARAM</KommuneNavn>
<BruttoInntekt>0</BruttoInntekt>
<Gjeldsgrad1>0.0</Gjeldsgrad1>
<Gjeldsgrad2>0.0</Gjeldsgrad2>
</Ligning>
<NaringsInteresser>
<Orgnr>937340303</Orgnr>
<StatusKode>A</StatusKode>
<StatusTekst>Aktivt</StatusTekst>
<Navn>SVAR DIREKTE AS</Navn>
<SelskForm>AS</SelskForm>
<Rolle>Eier</Rolle>
<Eierandel>5.0</Eierandel>
</NaringsInteresser>
<NaringsInteresser>
<Orgnr>931024280</Orgnr>
<StatusKode>A</StatusKode>
<StatusTekst>Aktivt</StatusTekst>
<Navn>HELT NYTT FORETAK AS</Navn>
<SelskForm>AS</SelskForm>
<Rolle>Ansvar</Rolle>
<Eierandel>0.0</Eierandel>
<VervKode>3</VervKode>
<VervTekst>Styremedlem</VervTekst>
</NaringsInteresser>
<Meldinger>
<MeldingsKode>30</MeldingsKode>
<MeldingsTekst>Navn/adresse-historikk ikke funnet på forespurt objekt.</MeldingsTekst>
</Meldinger>
</root>
This is the xslt code I am using.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" />
<xsl:strip-space elements="*" />
<xsl:template match="/">
<html>
<head>
<title>Wash Result</title>
</head>
<body>
<h2>Wash Result</h2>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="All">
<xsl:apply-templates select="Identifikasjon" />
<xsl:apply-templates select="Ligning" />
</xsl:template>
<xsl:template match="Identifikasjon">
<div class="accordion">
<div class="option">
<input type="checkbox" id="toggle1" class="toggle" />
<label class="title" for="toggle1">
Identifikasjon
</label>
<div class="content ">
<div class="display-inline">
<p>
<xsl:if test="Orgnr">
<span class="mr-3">
Orgnr: <strong>
<xsl:value-of select="Orgnr" />
</strong>
</span>
</xsl:if>
<xsl:if test="Dunsnr">
<span>
Dunsnr: <strong>
<xsl:value-of select="Dunsnr" />
</strong>
</span>
</xsl:if>
<xsl:if test="Internref">
<span>
Internref: <strong>
<xsl:value-of select="Internref" />
</strong>
</span>
</xsl:if>
</p>
</div>
</div>
</div>
</div>
</xsl:template>
<xsl:template match="Ligning">
<div class="accordion">
<div class="option">
<input type="checkbox" id="toggleLigning" class="toggle" />
<label class="title" for="toggleLigning">
Ligning
</label>
<div class="content">
<table border="1">
<tr>
<th>SkatteAr</th>
<th>Formue</th>
<th>EndringFormue</th>
<th>Inntekt</th>
<th>EndringInntekt</th>
<th>Skatt</th>
<th>SkatteKlasse</th>
<th>Kommunenr</th>
<th>KommuneNavn</th>
<th>BruttoInntekt</th>
<th>Gjeldsgrad1</th>
<th>Gjeldsgrad2</th>
</tr>
<xsl:for-each select="/root/Ligning">
<tr>
<td>
<xsl:value-of select="SkatteAr" />
</td>
<td>
<xsl:value-of select="Formue" />
</td>
<td>
<xsl:value-of select="EndringFormue" />
</td>
<td>
<xsl:value-of select="Inntekt" />
</td>
<td>
<xsl:value-of select="EndringInntekt" />
</td>
<td>
<xsl:value-of select="Skatt" />
</td>
<td>
<xsl:value-of select="SkatteKlasse" />
</td>
<td>
<xsl:value-of select="Kommunenr" />
</td>
<td>
<xsl:value-of select="KommuneNavn" />
</td>
<td>
<xsl:value-of select="BruttoInntekt" />
</td>
<td>
<xsl:value-of select="Gjeldsgrad1" />
</td>
<td>
<xsl:value-of select="Gjeldsgrad2" />
</td>
</tr>
</xsl:for-each>
</table>
</div>
</div>
</div>
</xsl:template>
The result is as follows.
result from the code
I want to stop duplicating the lines. (Ligning)
I'm experiencing an issue with an xsl cheatsheet. The generated DOM seems to be in wrong order. Here is my xsl :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="site-path" select="site-path" />
<xsl:param name="target" select="target" />
<xsl:param name="page-id" select="page-id" />
<xsl:variable name="portlet-id" select="portlet/portlet-id" />
<xsl:template match="portlet">
<xsl:variable name="device_class">
<xsl:choose>
<xsl:when test="string(display-on-small-device)='0'">hidden-xs</xsl:when>
<xsl:when test="string(display-on-normal-device)='0'">hidden-sm</xsl:when>
<xsl:when test="string(display-on-large-device)='0'">hidden-md</xsl:when>
<xsl:when test="string(display-on-xlarge-device)='0'">hidden-lg</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<div class="portlet {$device_class}">
<xsl:if test="not(string(display-portlet-title)='1')">
<h3 id="article_{$portlet-id}" class="heading"><xsl:value-of disable-output-escaping="yes" select="portlet-name" /></h3>
</xsl:if>
<ul class="news-list gallery news-cards">
<xsl:apply-templates select="document-list-portlet/document" />
<xsl:text disable-output-escaping="yes">
<![CDATA[<div class="clearfix"> </div>]]>
</xsl:text>
</ul>
</div>
</xsl:template>
<xsl:template match="document">
<xsl:if test="not(string(document-xml-content)='null')">
<xsl:variable name="vignette-id" select="document-xml-content/article/article-vignette/file-resource/resource-document-id" />
<xsl:variable name="attribute-id" select="document-xml-content/article/article-vignette/file-resource/resource-attribute-id" />
<li class="news-list-card-item">
<a href="{$site-path}?document_id={document-id}&portlet_id={$portlet-id}" class="news-card">
<div style="background-image: url(document?id={$vignette-id}&id_attribute={$attribute-id}&working_content=true)" class="news-card-image" />
<div class="news-card-wrapper">
<div class="news-card-content">
<div class="news-card-category">
<span>Catégorie</span>
</div>
<div class="news-card-title">
<xsl:value-of select="document-xml-content/article/document-title" />
</div>
</div>
</div>
</a>
<xsl:if test="(string(resource-is-votable)='1')">
<br />
<xsl:variable name="resource-score" select="resource-score" />
<img src="images/local/skin/plugins/rating/stars_{$resource-score}.png" alt="Score" title="Score" />
</xsl:if>
<xsl:if test="(string(is-download-stat)='1')">
<br />
#i18n{rating.resource_vote.labelDownloadCount} : <xsl:value-of select="resource-download-stat" />
</xsl:if>
</li>
</xsl:if>
</xsl:template>
After the render, the generated DOM is :
<li class="news-list-card-item">
<a class="news-card" href="jsp/site/Portal.jsp?document_id=35&portlet_id=100">
</a>
<div class="news-card-image" style="background-image: url(document?id=35&id_attribute=64&working_content=true)">
<a class="news-card" href="jsp/site/Portal.jsp?document_id=35&portlet_id=100">
<div class="news-card-wrapper">
<div class="news-card-content">
<div class="news-card-category">
<span>Catégorie</span>
</div>
<div class="news-card-title">Artu avec vignette 2</div>
</div>
</div>
</a>
</div>
</li>
Here is the expected HTML :
<li class="news-list-card-item">
<a href="#" class="news-card">
<div class="news-card-wrapper">
<div style="background-image: url(../../modules/news-card/image.jpg)" class="news-card-image"></div>
<div class="news-card-content">
<div class="news-card-category"><span>Mobilité</span>
</div>
<div class="news-card-title">Découvrez les neuf Autolib' customisées qui vont sillonner Paris</div>
</div>
</div>
</a>
</li>
Differences are :
In the expected, you got :
li > a > div >div > div ...
In the generated you got :
li > a
div > a > div > div > div
HEre is a smaller reproductible example :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="portlet">
<div class="portlet">
<ul class="news-list gallery news-cards">
<xsl:apply-templates select="document-list-portlet/document" />
</ul>
</div>
</xsl:template>
<xsl:template match="document">
<li class="news-list-card-item">
<a class="news-card">
<div style="background-image: url(hello_world.png)" class="news-card-image" />
<div class="news-card-wrapper">
<div class="news-card-content">
<div class="news-card-category">
<span>Catégorie</span>
</div>
<div class="news-card-title">
Title
</div>
</div>
</div>
</a>
</li>
</xsl:template>
</xsl:stylesheet>
Here is an example data used to generate my DOM :
<?xml version="1.0" encoding="UTF-8"?>
<portlet>
<portlet-name>Actualités projet</portlet-name>
<portlet-id>100</portlet-id>
<page-id>1</page-id>
<plugin-name>document</plugin-name>
<display-portlet-title>0</display-portlet-title>
<display-on-small-device>1</display-on-small-device>
<display-on-normal-device>1</display-on-normal-device>
<display-on-large-device>1</display-on-large-device>
<display-on-xlarge-device>1</display-on-xlarge-device>
<document-list-portlet>
<document>
<document-id>35</document-id>
<document-date-publication>11/07/2017</document-date-publication>
<document-xml-content>
<article>
<document-id>35</document-id>
<document-title>Artu avec vignette 2</document-title>
<document-summary>Artu avec vignette 2</document-summary>
<document-date-begin>11/07/2017</document-date-begin>
<document-date-end>
<document-categories>
<article-url>http://</article-url>
<article-attachment>
<article-vignette>
<file-resource>
<resource-document-id>35</resource-document-id>
<resource-attribute-id>64</resource-attribute-id>
<resource-content-type>image/jpeg</resource-content-type>
</file-resource>
<file-size>134783</file-size>
</article-vignette>
<article-body><p>Artu avec vignette 2</p></article-body>
</article-attachment>
</document-categories>
</document-date-end>
</article>
</document-xml-content>
</document>
</document-list-portlet>
</portlet>
I'm using Google Chrome 59.
I'm searching the issue since 2 days and i'm currently lost. Can you help me?
Thx,
SLED
I just solved my issue by adding a in my background-image div :
<div class="news-card-wrapper">
<div style="background-image: url(document?id={$vignette-id}&id_attribute={$attribute-id}&working_content=true)" class="news-card-image" > </div>
<div class="news-card-content">
<div class="news-card-category">
<span>Catégorie</span>
</div>
<div class="news-card-title">
<xsl:value-of select="document-xml-content/article/document-title" />
</div>
</div>
</div>
Thanks for all your answer and for #MartinHonnen explaination.
The data comes from the server, usually two rows, but sometimes it's more. So I try to make the list dynamic change.
<xsl:template match="Event">
<ul class="lines">
<xsl:apply-templates select="Line"/>
</ul>
</xsl:template>
<xsl:template match="Line">
<li class="something">
<a href="">
<span class="result"><xsl:value-of select="#result"/></span>
<span class="odds"><xsl:value-of select="#odds"/></span>
</a>
</li>
</xsl:template>
I have to count the number of "li" and if it's more than 2, i have to change the class of "li"
Within the template matching Line you can access the total number of Line elements within this Event using the last() function (which returns the index number of the last node in the "current node list" determined by the select expression of the apply-templates that caused this template to fire, which in this case is the set of Line children of a particular Event).
<li>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="last() <= 2">something</xsl:when>
<xsl:otherwise>somethingElse</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
How about something like this:
<xsl:template match="Event">
<ul class="lines">
<xsl:apply-templates select="Line"/>
</ul>
</xsl:template>
<xsl:template match="Line" name="Line">
<xsl:param name="classVal" select="'something'" />
<li class="{$classVal}">
<a href="">
<span class="result">
<xsl:value-of select="#result"/>
</span>
<span class="odds">
<xsl:value-of select="#odds"/>
</span>
</a>
</li>
</xsl:template>
<xsl:template match="Line[count(../Line) > 1]">
<xsl:call-template name="Line">
<xsl:with-param name="classVal" select="'somethingElse'" />
</xsl:call-template>
</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
<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