In Composite C1, How to apply same blog application/module to multiple pages - blogs

I have successfully added a blog application to a new page called "Blog". Now I have a different "AboutUs" page on which I want a list of latest five blogs postings. For this I created a new XSLT function similar to Community.Blog.Renderer which can display the blogs as per my requirement.
Next, I added blog application to "AboutUs" page. But it seems this is a different application. What I want to achieve:
A small widget on "AboutUs" page that displays list of latest 5 blogs posted on the "Blog" page.
A "Read More" button in each such widget, which when clicked will redirect to the corresponding blog on the "Blog" page.
I am new to composite C1 and till this far I have liked it very much. I hope, composite C1 can handle my requirements somehow and doesn't let me down.
Appreciating your concern.

For keeping this thread clean, here is the answer posted by Inna on codeplex discussion forum:
You can achieve this by creating a simple XSLT:
Create XSLT for example named Composite.Community.Blog.Latest
On the Function Call tab add two functions "Composite.Community.Blog.Entries.GetEntriesXml" and "Composite.Community.Blog.XsltExtensions", Source code like this
<f:functions xmlns:f="http://www.composite.net/ns/function/1.0">
<f:function name="Composite.Community.Blog.Entries.GetEntriesXml" localname="GetEntriesXml">
<f:param name="PropertyNames">
<f:paramelement value="Date" />
<f:paramelement value="Teaser" />
<f:paramelement value="PageId" />
<f:paramelement value="Id" />
<f:paramelement value="Title" />
</f:param>
<f:param name="OrderByField" value="Date" />
<f:param name="OrderAscending" value="False" />
<f:param name="PageSize" value="5" />
</f:function>
<f:function name="Composite.Community.Blog.XsltExtensions" localname="XsltExtensions" />
</f:functions>
Make sure that GetEntriesXml's Selected Fields contain PageId, Date and Title fields, you will need them to generate Blog Entry URL.
On the Template tab you will have something like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:in="http://www.composite.net/ns/transformation/input/1.0" xmlns:lang="http://www.composite.net/ns/localization/1.0" xmlns:f="http://www.composite.net/ns/function/1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:be="#BlogXsltExtensionsFunction" exclude-result-prefixes="xsl in lang f be">
<xsl:template match="/">
<html>
<head></head>
<body>
<ul>
<xsl:for-each select="/in:inputs/in:result[#name='GetEntriesXml']/Entries">
<li>
<h3>
<xsl:value-of select="#Title" />
</h3>
<p>
<xsl:value-of select="#Teaser" />
</p>
Read more...
</li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Then insert this XSLT where you want to show list of the 5 latest blog entries. (note: you should not to add blog application to the page where you want to show list of latest entries.)

Related

Is there something invalidating my code from being accepted as an XML file?

Getting an error that this body of code isn't valid as part of an XSL file. That's the only feedback that this document system gives me. This is part of a larger document but I thought I would try isolating the issue to see if it's in the first half of the document
<xsl:template match="ws:Worker_Sync">
<File etv:separator="
">
<Header etv:separator=";">
<HeaderItem1>EEID</HeaderItem1>
<HeaderItem2>FirstNAME</HeaderItem2>
<HeaderItem3>LastNAME</HeaderItem3>
<HeaderItem4>INTNAME</HeaderItem4>
<HeaderItem5>OHDATE</HeaderItem5>
<HeaderItem6>SALARY</HeaderItem6>
</Header>
<xsl:apply-templates select="ws:Worker"/>
<Footer>
<WorkerCount etv:number="totalCount">
</WorkerCount>
<DateTimeviaXpath>
<etv:class etv:name="FormatDates" etv:dateFormat="yyyy-MM-dd"/>
<etv:class etv:name="FormatTime" etv:timeFormat="HH-mm-ss"
<xsl:value-of select="current-dateTime"/>
</DateTimeviaXpath>
</Footer>
</File>
</xsl:template>
This etv:class element
<etv:class etv:name="FormatTime" etv:timeFormat="HH-mm-ss"
needs to be
<etv:class etv:name="FormatTime" etv:timeFormat="HH-mm-ss"/>

Binding HTML elements to XML fields

I am trying "Tutorial 9 - Using XML as a Data Source" of the book "New Perspectives on XML, 2nd Edition by Patrick Carey". I found the materials from this link from a simple web search.
This is part of .htm file.
<html>
<head>
<title>Freezing Point Refrigerators</title>
<link href="styles1.css" rel="stylesheet" type="text/css" />
<xml id="pageInfo" src="fpinfo.xml"></xml>
</head>
<body>
<div id="pageTitle" datasrc="#pageInfo" datafld="title"></div>
<div id="pageSubtitle" datasrc="#pageInfo" datafld="subtitle"></div>
<div id="pageText" datasrc="#pageInfo" datafld="purpose"></div>
<div id="pageAuthor">For more information, contact:
<a datasrc="#pageInfo" datafld="authorEmail">
<span datasrc="#pageInfo" datafld="author"></span>
</a>.
</div>
Following is the content of the "fpinfo.xml" file.
<?xml version="1.0" encoding="UTF-8" ?>
<information>
<title>Freezing Point Refrigerators</title>
<subtitle>Staff Information Page</subtitle>
<purpose>
This page contains information on the staff of Freezing Point
Refrigerators. Staff members are divided into four groups: Accounting,
Sales, Manufacturing, and Advertising. Each employee's name, department,
position, phone number, years employed, and job status (full- or
part-time) is reported.
</purpose>
<author>Catherine Davis</author>
<authorEmail>mailto:cdavis#freezingpoint.com</authorEmail>
</information>
This is the expected output:
But this is what I get in IE browser:
Why the title and other xml fields are not correctly displayed? Following is the developer tools view.
Even the xml line <xml id="pageInfo" src="fpinfo.xml"></xml> is in the .htm header field, it can be seen under body tag of the developer view. What am I doing wrong here. Thank you.
It seems these examples on W3Schools are working.
And also this one is interesting, with a triggering button though.
(But it became more complicated, I don't even get why. That old code above in the question was beautiful, clear, one-lined. Personal Growl OFF.)

Why my app-template is not taking effect on all its children in XSLT?

I have the following xml:
<page>
<link name="Index">index.jsp</link>
<link name="Welcome">welcome.jsp</link>
</page>
I am using the following xsl file to produce a html file:
....
<xsl:template match="/page/link" >
<a href="{/page/link}" > <xsl:value-of select="#name" /> </a>
</xsl:template >
However, the both links are taking the value of the first child element as the reference, hence both links take the user to index.jsp
could you guys give me some advices as I am new to XSLT. Thanks
This is because you are using an absolute path in your AVT, which will result in the first value matched. Instead, do this:
<xsl:template match="/page/link" >
<a href="{.}" > <xsl:value-of select="#name" /> </a>
</xsl:template >
JLRishe has given you the answer, I will try giving the advice!
When you write XSLT code, always be aware of the context. XPath expressions select relative to the context. Within a template rule with match="/page/link", the context item is a "link" element. When the context item is a link element, /page/link goes up to the root of the tree (because of the initial "/") and then selects all the page children, and then selects all their link children. Which gives you all the links.
In XSLT 1.0 (which you appear to be using) an attribute value template such as {/page/link} will display the first link. In XSLT 2.0 it will display all the selected links, space-separated. Neither is what you want.

Can XPath locate nodes after arbitrary occurrences of text in non-valid markup?

I have a document written by a naughty web developer, which looks something like:
<div id="details">
Here is some text without a p tag. Oh, let's write some more.
<br>
<br>
And some more.
<table id="non-unique">
...
</table>
Replaces the following numbers:
<table id="non-unique">
... good stuff in here
</table>
</div>
So, it's not well marked up. I need to get hold of the table with the good stuff in it, however, it doesn't have a unique id value and it is not always in the same order, or last in the div etc.
The only running theme is that it always follows the text Replaces the following numbers:, though this text may be as it is in the example above, or sometimes in a h4 element!
Is it possible to use an XPath expression to wrangle this table out by searching for the replaces string and then asking for the next table element??
Thanks!
That looks valid to me:
//text()[contains(.,"Replaces the following numbers")]/following-sibling::table[1]
There's no rule that id's must be unique.
Use:
//node()[self::h4 or self::text()]
[normalize-space() = 'Replaces the following numbers:']
/following-sibling::*[1][self::table]
XSLT - based verification:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of select=
"//node()[self::h4 or self::text()]
[normalize-space() = 'Replaces the following numbers:']
/following-sibling::*[1][self::table]
"/>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on the provided document (corrected to be made well-formed XML document):
<div id="details">
Here is some text without a p tag. Oh, let's write some more.
<br />
<br />
And some more.
<table id="non-unique">
...
</table>
Replaces the following numbers:
<table id="non-unique">
... good stuff in here
</table>
</div>
the XPath expression is evaluated and the selected node(s) are copied to the output:
<table id="non-unique">
... good stuff in here
</table>
When the same transformation (XPath expression) is applied on this XML document:
<div id="details">
Here is some text without a p tag. Oh, let's write some more.
<br />
<br />
And some more.
<table id="non-unique">
...
</table>
<h4>Replaces the following numbers:</h4>
<table id="non-unique">
... good stuff in here
</table>
</div>
again the wanted element is selected and output:
<table id="non-unique">
... good stuff in here
</table>
No, as XPath requires well-formed Xml to run on.
cf. this answer, which provides some additional info.

Colorize Unique Elements in XML using XSLT

I currently have an XML document which basically consists of several conversations between people just like an IM conversation.
I have each conversation displaying how I want to so far, except I want each name to be a unique color for readability.
How I have it is that the XML is transformed into HTML with CSS. I'd like to use XPath and XSL 1.0 for this:
XML
<wtfwhispers xmlns="http://wtfwhispers.kicks-ass.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://wtfwhispers.kicks-ass.org wtfwhispers.xsd">
<conversation uuid="Diedrick">
<datePosted>2010-05-30</datePosted>
<description>What a great description</description>
<dialog>
<dialogDate>2009-12-22</dialogDate>
<whisper>
<whisperTime>03:55:00</whisperTime>
<speaker>Stubbymush</speaker>
<babble>i said something here</babble>
</whisper>
<whisper>
<whisperTime>03:56:00</whisperTime>
<speaker>Jaymes</speaker>
<babble>what did you say?</babble>
</whisper>
<whisper>
<whisperTime>03:56:00</whisperTime>
<speaker>Stubbymush</speaker>
<babble>i said something here!</babble>
</whisper>
...
<whisper>
<whisperTime>03:57:00</whisperTime>
<speaker>Stubbymush</speaker>
<babble>gawd ur dumb</babble>
</whisper>
</dialog>
</conversation>
</wtfwhispers>
Ideally what I would want is to get an output of <p class="speaker one"> for the first speaker, <p class="speaker two"> for the 2nd and so on.
I was trying to use and the Meunchian Method to find how many unique speakers I have but what I have was not working:
...
<xsl:key name="speakerList" match="wtf:whisper" use="wtf:speaker" />
<xsl:template match="/">
<html lang="en">
<body>
<p>
<xsl:value-of select="count( key( 'speakerList', wtf:speaker ) )" />
</p>
</body>
</html>
</xsl:template>
...
When I input 'Jaymes' or 'Stubbymush' I'd get the correct number of times that speaker spoke, but not how many speakers were in the conversation total.
Thanks in advance and if you have any suggestions for simpler methods because I'm overcomplicating it please advise.
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://wtfwhispers.kicks-ass.org"
>
<xsl:output method="text"/>
<xsl:key name="kSpeakerByVal" match="w:speaker" use="."/>
<xsl:template match="/">
<xsl:value-of select=
"count(
/*/*/*/w:whisper/w:speaker
[generate-id()
=
generate-id(key('kSpeakerByVal',.)[1])
]
)
"/>
</xsl:template>
</xsl:stylesheet>
when applied on the provided XML document, produces the correct speaker count:
2