Hi i have a web site on umbraco 4 CMS.Also i want to install a blog plugin.
Is there possible pull news from blog into my site.
Example i want to publish news/post everyday from blog and create link to blog page from my web site.
Preview :
thx for ur help
Something like this should work if you are using Blog4Umbraco. It requires that you have the source as a ContentPicker parameter and the maxItems as a number. It does some things like format the date for sorting properly and checking for posts in the past (in case they are scheduled).
<xsl:param name="currentPage"/>
<xsl:variable name="documentTypeAlias" select="string('BlogPost')"/>
<xsl:variable name="source" select="/macro/source"/>
<xsl:variable name="maxItems" select="/macro/maxItems" />
<xsl:template match="/">
<xsl:variable name="currPosts" select="umbraco.library:GetXmlNodeById($source)//BlogPost [#isDoc and umbraco.library:DateDiff(#createDate, umbraco.library:CurrentDate(), 'm') < 0]"/>
<xsl:for-each select="$currPosts">
<xsl:sort select="umbraco.library:FormatDateTime(#createDate, 'yyyyMMdd')" data-type="number" order="descending" />
<xsl:if test="position() <= $maxItems">
<div>
<h4><xsl:value-of select="#nodeName"/></h4>
<span class="homeBlogDate"><xsl:value-of select="umbraco.library:FormatDateTime(#createDate, 'M.dd.yy')"/></span>
<p>
<xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(bodyText), 140, ' ')" disable-output-escaping="yes"/>...
</p>
<a href="{umbraco.library:NiceUrl(#id)}" class="postReadMore">
read more >
</a>
</div>
</xsl:if>
</xsl:for-each>
</xsl:template>
Related
Actually I have started with my XSLT work recently, I am facing difficulty in solving one of the requirement.
I am trying to fetch an substring from DATA element in the mentioned input i,e is ECHO and OKAY these codes need to be replaced with the values present under CODE/ECHO and CODE/OKAY in the same input. I had tried storing the substring in a variable and as the variable value and tag value would be same, I have tried to fetch that in . But its not working.
Is it that we cant use variables in the XPATHS or there is some other representation which needs to be used? Could anyone please help me with this.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output omit-xml-declaration="yes" />
<xsl:param name="break" select="'
'" />
<xsl:template match="/">
<xsl:variable name="String" select="substring(DATA, (string-length(substring(DATA,0,77)) + 1), 4)" />
<xsl:variable name="String1" >
<xsl:value-of select="Root/CODES/$String" />
</xsl:variable>
<xsl:value-of select="$break" />
<xsl:value-of select="$String1" />
</xsl:for-each>
</xsl:template>
Input:
<?xml version='1.0' encoding='utf-8'?>
<ROOT>
<INPUT>
<I_FILENAME>ERES</I_FILENAME>
</INPUT>
<CODES>
<ECHO>A1</ECHO>
<OKAY>A2</OKAY>
</CODES>
<TABLES>
<T_ER>
<item>
<DATA> HEADERERESRGCITIS220190301124112000000RGERSD46</DATA>
</item>
<item>
<DATA>000000 ABCD EF 0000000000 2018-11-060000000000EF 000000000000010000ECHO00400300000000000XXXXXX 000{ P 2018-11-05</DATA>
</item>
<item>
<DATA>000000 ABCD EF 0000000000 2018-11-060000000000EF 000000000000010000OKAY00400300000000000XXXXXX 000{ P 2018-11-05</DATA>
</item>
<item>
<DATA>TRAILERERESRGCITIS220190301124112000000001570000</DATA>
</item>
</T_ER>
</TABLES>
</ROOT>
EXPECTED OUT PUT:
HEADERERESRGCITIS220190301124112000000RGERSD46
000000 ABCD EF 0000000000 2018-11-060000000000EF 000000000000010000A100400300000000000XXXXXX 000{ P 2018-11-05
000000 ABCD EF 0000000000 2018-11-060000000000EF 000000000000010000A200400300000000000XXXXXX 000{ P 2018-11-05
<xsl:template match="INPUT|CODES">
</xsl:template>
<xsl:template match="TABLES">
<xsl:variable name="break" select="'
'" />
<xsl:for-each select="T_ER/item"><xsl:value-of select="$break"></xsl:value-of>
<xsl:value-of select="DATA"/>
</xsl:for-each>
</xsl:template>
Currently, I have many "xsl:choose" conditions in my file - one "xsl:choose" for a single letter, and it works well.
I try to simplify this situation by replacing many "xsl:choose" with 'for-each' loop - however with no luck.
It's seems to me, that count() inside 'for-each' always returns 0.
I'm curious, because the same count() without 'for-each' works OK.
Pls help.
<?xml version="1.0"?>
<stocks>
<names date="10/30/2013" time="20:37:12">
<name>WGOS1</name>
<name>WGOS2</name>
<name>WGOS3</name>
<name>WGOS4</name>
<name>WGOS5</name>
</names>
<loc>
<slot>P</slot>
<slot>P</slot>
<slot>P</slot>
<slot>P</slot>
<slot>H</slot>
<slot>S</slot>
</loc>
<loc>
<slot>P</slot>
<slot>P</slot>
<slot>P</slot>
<slot>S</slot>
When I use 'count' function to count values eg. 'B' in 'loc' node, it's works OK
<xsl:variable name="color-table">
<var code="A">pink</var >
<var code="B">silver</var>
<var code="P">red</var>
<var code="D">pink</var>
<var code="H">yellow</var>
<var code="S">lightblue</var>
<var code="T">green</var>
<var code="W">pink</var>
</xsl:variable>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="count(/stocks/loc[$pos]/slot [. eq 'B']) > 0">
<td class="slot-B">
<xsl:value-of select="count(/stocks/loc[$pos]/slot [. eq 'B'])"/>
<xsl:text>B</xsl:text>
</td>
</xsl:when>
</xsl:choose>
But when I try to do the same inside for-each loop - test condition fails, due the count() result is always 0.
<xsl:for-each select="$color-table/var">
<xsl:variable name="p" select="#code"/>
<xsl:choose>
<xsl:when test="count(/stocks/loc[$pos]/slot [. eq $p]) > 0">
<td class="slot-$p">
<xsl:value-of select="count(/stocks/loc[$pos]/slot [. eq $p])"/>
<xsl:value-of select="$p"/>
</td>
</xsl:when>
</xsl:choose>
</xsl:for-each>
The $color-table variable refers to a temporary tree, so when you're inside a
<xsl:for-each select="$color-table/var">
/ is the root of that temporary tree, not the root of the original document, and thus /stocks/loc[$pos]/slot will not find any nodes.
You need to store the outer / in another variable before you go into the for-each.
<xsl:variable name="slash" select="/" />
<xsl:for-each select="$color-table/var">
<xsl:variable name="p" select="#code"/>
<xsl:choose>
<xsl:when test="count($slash/stocks/loc[$pos]/slot [. eq $p]) > 0">
<td class="slot-{$p}">
<xsl:value-of select="count($slash/stocks/loc[$pos]/slot [. eq $p])"/>
<xsl:value-of select="$p"/>
</td>
</xsl:when>
</xsl:choose>
</xsl:for-each>
But rather than iterating over the color-table, it may be more efficient to just for-each-group over the slots themselves
<xsl:for-each-group select="/stocks/loc[$pos]/slot" group-by=".">
<td class="slot-{current-grouping-key()}">
<xsl:value-of select="count(current-group())" />
<xsl:value-of select="current-grouping-key()" />
</td>
</xsl:for-each-group>
I have some strings I want to test to see if they contain specific words. The words in question are in a lookup node, and if there is a match the word in the string needs to be tagged. I have a script that works almost ok, but I want to know if I'm using the best format, as I believe it's rather resource consuming, and not very foolproof.
Example xml :
<Main>
<NTUS>
<NTU>match</NTU>
<NTU>test</NTU>
</NTUS>
<Folder id="update">
<about>This content is not in a span so we ignore it completely, even if we would have a match</about>
<Title>
<span class="string simple" lang="en">Some test content containing a single match</span>
</Title>
<Content>
<span class="string complex" lang="en">Also keywords in sub elements should <strong>pass the test</strong>, and match.</span>
</Content>
</Folder>
</Main>
My current xslt :
<xsl:param name="units">
<xsl:copy-of select="//NTU"/>
</xsl:param>
<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="NTUS"/>
<xsl:template match="text()[ancestor::span]">
<xsl:analyze-string select="." regex="\s+">
<xsl:matching-substring>
<xsl:value-of select="."/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:variable name="theWord" select="."/>
<xsl:choose>
<xsl:when test="$units/*[text()=$theWord]">
<ntu>
<xsl:value-of select="."/>
</ntu>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
results in following :
<Main>
<Folder id="update">
<about>This content is not in a span so we ignore it completely, even if we would have a match</about>
<Title>
<span class="string simple" lang="en">Some <ntu>test</ntu> content containing a single <ntu>match</ntu></span>
</Title>
<Content>
<span class="string complex" lang="en">Also keywords in sub elements should <strong>pass the <ntu>test</ntu></strong>, and match.</span>
</Content>
</Folder>
</Main>
Which is almost ok apart from the last node, as the [match] is at the end of the sentence and therefore not passing the regex. I can adjust it to make it match, but it could become pretty complex then, so i want to know if there are better ways to address this problem.
EDIT : there seems to be a small misbehaviour when you use a comma delimited list (might be on other occasions also, but this one I noticed)...
So for instance following xml
<Main>
<NTUS>
<NTU>OPTION1</NTU>
<NTU>OPTION2</NTU>
<NTU>OPTION3</NTU>
<NTU>OPTION4</NTU>
<NTU>OPTION5</NTU>
</NTUS>
<local xml:lang="en">
<span>Test string containing some comma seperarated lookup values: OPTION1, OPTION2, OPTION3, OPTION4, OPTION5</span>
</local>
Returns following when the script is applied :
<span>Test string containing some comma seperarated lookup values: <ntu>OPTION1</ntu>, OPTION2, <ntu>OPTION3</ntu>, OPTION4, <ntu>OPTION5</ntu></span>
so every second match is skipped. Any idea what is causing this behaviour ?
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:variable name="vPatterns" select=
"string-join(/*/NTUS/*, '|')"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="span//text()">
<xsl:analyze-string select="." regex=
"(^|(\P{{L}})+)({$vPatterns})($|(\P{{L}})+)">
<xsl:non-matching-substring><xsl:value-of select="."/></xsl:non-matching-substring>
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)"/>
<ntu><xsl:value-of select="regex-group(3)"/></ntu>
<xsl:value-of select="regex-group(4)"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied to the provided XML document:
<Main>
<NTUS>
<NTU>match</NTU>
<NTU>test</NTU>
</NTUS>
<Folder id="update">
<about>This content is not in a span so we ignore it completely, even if we would have a match</about>
<Title>
<span class="string simple" lang="en">Some test content containing a single match</span>
</Title>
<Content>
<span class="string complex" lang="en">Also keywords in sub elements should <strong>pass the test</strong>, and match.</span>
</Content>
</Folder>
</Main>
the wanted, correct result is produced:
<Main>
<NTUS>
<NTU>match</NTU>
<NTU>test</NTU>
</NTUS>
<Folder id="update">
<about>This content is not in a span so we ignore it completely, even if we would have a match</about>
<Title>
<span class="string simple" lang="en">Some <ntu>test</ntu> content containing a testmatch or a single <ntu>match</ntu></span>
</Title>
<Content>
<span class="string complex" lang="en">Also keywords in sub elements should <strong>pass the <ntu>test</ntu></strong>, and <ntu>match</ntu>.</span>
</Content>
</Folder>
</Main>
I am making controls on a web page (comboboxes) with Saxon-CE and Xslt 2.0. I am having trouble in passing the values of multiple control to a template that uses the values from that control to process the document. Here is what I have:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ixsl="http://saxonica.com/ns/interactiveXSLT"
extension-element-prefixes="ixsl">
<xsl:template match="/">
<xsl:result-document href="#comboBox1">
<select id="myBox1">
<option value="1">One</option>
<option value="2">two</option>
</select>
</xsl:result-document>
<xsl:result-document href="#comboBox2">
<select id="myBox2">
<option value="A">Letter-A</option>
<option value="B">Letter-B</option>
</select>
</xsl:result-document>
</xsl:template>
<xsl:template match="select[#id='myBox1'] mode=ixsl:onchange">
<xsl:variable name="control1" select="."/>
<xsl:variable name="numVal" select="ixsl:get($control1,'value')"/>
<xsl:call-template name="displayStuff">
<xsl:with-param name="field1" select="$numVal"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="select[#id='myBox2'] mode=ixsl:onchange">
<xsl:variable name="control2" select="."/>
<xsl:variable name="letVal" select="ixsl:get($control2,'value')"/>
<xsl:call-template name="displayStuff">
<xsl:with-param name="field2" select="$letVal"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="displayStuff">
<xsl:param name="field1" select="0"/>
<xsl:param name="field2" select="Z">
<xsl:result-document href="#display" method="ixsl:replace-content">
<xsl:text>Number: </xsl:text> <xsl:value-of select="$field1"/><br/>
<xsl:text>Letter: </xsl:text> <xsl:value-of select="$field2"/><br/>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
The problem is that each control returns the correct value to the display template for an then item just changed, but not the other item.
For example if I select 1 in the first dropbox I get Number: 1 Letter: Z
but now if I change the vale of the second dropbox (for lets say to A) I get Number: 0 Letter:A.
How can I make sure what is passed to the display template is the current selected value of all the dropboxes, not the one just changed?
Instead of passing the current values of the controls as parameters to the displayStuff template, why not have that template access them directly from the HTML page by means of XPath expressions?
I suspect you could combine all this into a single template:
<xsl:template match="select[#id=('myBox1', 'myBox2')] mode=ixsl:onchange">
<xsl:variable name="control1" select="."/>
<xsl:variable name="numVal" select="ixsl:get(id('myBox1'),'value')"/>
<xsl:variable name="letVal" select="ixsl:get(id('myBox2'),'value')"/>
<xsl:result-document href="#display" method="ixsl:replace-content">
<xsl:text>Number: </xsl:text> <xsl:value-of select="$numVal"/><br/>
<xsl:text>Letter: </xsl:text> <xsl:value-of select="$letVal"/><br/>
</xsl:result-document>
</xsl:template>
I have this XML code
<parag>blah blah blah</parag>
<parag>blah blah, refer to <linkCode code1="a" code2="b" code3="c"/> for further details.</parag>
I can't figure out how to get the link to stay in the middle of the parent text. The following code
<xsl:for-each select="parag">
<p><xsl:value-of select="text()"/>
<xsl:for-each select="linkCode">
this link
</xsl:for-each>
</p>
</xsl:for-each>
produces
<p>blah blah blah</p>
<p>blah blah, refer to for further details.this link</p>
What I want is
<p>blah blah blah</p>
<p>blah blah, refer to this link for further details.</p>
Any ideas? No, I don't have control over the content of the XML.
Use just simple overriding of the identity rule:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" />
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="linkCode">
this link
</xsl:template>
<xsl:template match="parag">
<p><xsl:apply-templates select="node()|#*"/></p>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on the following XML document (the provided fragment wrapped into a single top element -- to get a well-formed XML document):
<t>
<parag>blah blah blah</parag>
<parag>blah blah, refer to <linkCode code1="a" code2="b" code3="c"/> for further details.</parag>
</t>
the wanted, correct result is produced:
<t>
<p>blah blah blah</p>
<p>blah blah, refer to this link for further details.</p>
</t>
And if you want to have the top element not output:
just add this template:
<xsl:template match="/*"><xsl:apply-templates/></xsl:template>
So, the complete code becomes:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" />
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="linkCode">
this link
</xsl:template>
<xsl:template match="parag">
<p><xsl:apply-templates select="node()|#*"/></p>
</xsl:template>
<xsl:template match="/*"><xsl:apply-templates/></xsl:template>
</xsl:stylesheet>