A basic XSLT question

Topics: XSLT
Oct 27, 2010 at 7:25 PM

Hi all,

I have a pretty basic question, but i've been strugling with it for a while now.

When i call a function in a Page templates, they return XML which i guess is pretty neat. My problem is that i don't know how to format it to something usefull.

Here's a example

<xsl:variable name="metaDescription">		
<f:function xmlns:f="http://www.composite.net/ns/function/1.0" name="Volleyball.Meta.Metatags.GetMetatagsXml">
  <f:param name="PropertyNames">
    <f:paramelement value="Id" />
    <f:paramelement value="Description" />
  </f:param>
</f:function>
</xsl:variable>

My variable $metaDescription now holds this:

<Metatags Id="bf1de755-9984-4566-a769-2c7489af14ae" Description="DESCRIPTION!"></Metatags>

 But i only need the attribute, "Description", How do i do it?

I'm sure it's pretty basic XSLT, but I just can't get it right.

 

Regards

 Martin

Oct 27, 2010 at 10:20 PM

<xsl:value-of select="$metaDescription/Metatags/@Description" />

Coordinator
Oct 28, 2010 at 12:41 AM

Hi Boedlen


If you define variable $metaDescription this way, you have markup for a C1 function call inside of that variable rather than function call's result.

 
<f:function xmlns:f="http://www.composite.net/ns/function/1.0" name="Volleyball.Meta.Metatags.GetMetatagsXml">
  <f:param name="PropertyNames">
    <f:paramelement value="Id" />
    <f:paramelement value="Description" />
  </f:param>
</f:function>

instead of

<Metatags Id="bf1de755-9984-4566-a769-2c7489af14ae" Description="DESCRIPTION!"></Metatags>

I can suggest 2 ways around it:

1) You can use "Function calls" tab, and call your function there, the result of called function will be in a part of "input xml" for your xslt-function, and by clicking "Preview" you will see an example of XPath that leads to 

<Metatags Id="bf1de755-9984-4566-a769-2c7489af14ae" Description="DESCRIPTION!"></Metatags>


2) You can use one of ours standard xslt extensions to "execute" the function markup you have. The code will look like:

<xsl:stylesheet ......   xmlns:c1="http://c1.composite.net/StandardFunctions" >
......
<xsl:variable name="GetMetaDescriptionMarkup">		
<f:function xmlns:f="http://www.composite.net/ns/function/1.0" name="Volleyball.Meta.Metatags.GetMetatagsXml">
  <f:param name="PropertyNames">
    <f:paramelement value="Id" />
    <f:paramelement value="Description" />
  </f:param>
</f:function>
</xsl:variable>

<xsl:value-of select="c1:CallFunction($GetMetaDescriptionMarkup)/Metatags/@Description" />
or
<xsl:value-of select="c1:CallFunction($GetMetaDescriptionMarkup)/@Description" />

You can read a complete description here http://docs.composite.net/C1/XSLT/Calling-C1-Functions.aspx

Coordinator
Oct 28, 2010 at 4:17 AM

In case you are just looking for a way to get a "description" meta tag into your templates:

Just put <rendering:page.metatag.description /> in your template html head section - this will give you the meta description tag, using the page's description.

More info about therendering:page.metatag.description tag on http://docs.composite.net/C1/HTML/Guide-to-Templates-in-C1.aspx/A-Closer-Look-at-the-Template-Markup

Oct 28, 2010 at 5:10 PM

Thank you all for your replies, i've been trying your suggestions but i still can't get it to work.

My complete Page template looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:f="http://www.composite.net/ns/function/1.0" xmlns:lang="http://www.composite.net/ns/localization/1.0" xmlns:c1="http://c1.composite.net/StandardFunctions" xmlns:rendering="http://www.composite.net/ns/rendering/1.0" xmlns:asp="http://www.composite.net/ns/asp.net/controls">
	<head>
		<title>
			<rendering:page.title />

		</title>
		<rendering:page.metatag.description />
		
		<link rel="stylesheet" type="text/css" media="screen" href="/Frontend/Styles/style.css" />

	</head>
	<body>
	
	<div id="wrapper">	
		
		<xsl:variable name="GetMetaDescriptionMarkup">		
<f:function xmlns:f="http://www.composite.net/ns/function/1.0" name="Volleyball.Meta.Metatags.GetMetatagsXml">
  <f:param name="PropertyNames">
    <f:paramelement value="Id" />
    <f:paramelement value="Description" />
  </f:param>
</f:function>
</xsl:variable>	 

<xsl:value-of select="c1:CallFunction($GetMetaDescriptionMarkup)/Metatags/@Description" />
		
		
		
	</div>
	</body>
</html>
And if I visit the page that uses this template i get this output:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:c1="http://c1.composite.net/StandardFunctions">
	<head>
		<title>Forside</title>
		<link rel="stylesheet" type="text/css" media="screen" href="/Frontend/Styles/style.css" />
		<!--The following C1 head tags are only emitted when you are logged in-->
		<link rel="schema.C1" href="http://www.composite.net/ns/c1/seoassistant" />
		<meta name="C1.menutitle" content="Forside" />
		<meta name="C1.urltitle" content="Herning-Volleyball-klub" />
	</head>

	<body>
		<div id="wrapper">
			<variable name="GetMetaDescriptionMarkup">
  <Metatags Id="bf1de755-9984-4566-a769-2c7489af14ae" Description="DESCRIPTION!" />
</variable>
			<value-of select="c1:CallFunction($GetMetaDescriptionMarkup)/Metatags/@Description" />
		</div>
	</body>
</html>

I must be doing something wrong :-)

I found out about the tag to get the description, but the question is more about how to use output from C1 functions rather that getting the description.

I hope someone can see my wrong doings, and can tell me what's wrong in the above template.

 

Regards

 Martin

 

 

 

Coordinator
Oct 28, 2010 at 6:55 PM

Hi Martin

 

In C1 Page layout is an xml file, and by default there's no XSLT over it. In short, request to a C1 page processed in the following scheme:

1) Page template is taken and all <f:function ... /> tags inside are execuded recursively

2) The result Xml is transformed into ASP.NET controls, so both XSLT-functions and ASP.NET controls can co-exist on the same page

3)  ASP.NET controls render them-self 

4)  XHTML is being formatted, and all the C1 page links are converted to friendly urls.

 

So processing page template does not do an xslt transformation, and as you can see in the output, the function call was replaced with its result:

<Metatags Id="bf1de755-9984-4566-a769-2c7489af14ae" Description="DESCRIPTION!" />

xslt-tags lost their namespace, but in any other sense - were not processed.

 

If you want to do an XSLT transformation, you should create an "xslt function" and put it inside page layout. Choose "Functions" perspective, right-click on "Xslt functions" tree node and choose "Add xslt function".

In this video http://www.youtube.com/watch?v=HsfJjrmwmH4 from 2:08 there's an example how xslt-function editor looks like. Inside the editor, choose "Function calls" tab and add a call to "Volleyball.Meta.Metatags.GetMetatagsXml",

click the "Preview", you will see what xml will be the input for your XSLT function, and what is the output.

The next step would be to edit function's template, you will need to add something like:

<xsl:value-of select="/in:inputs/in:result[@name='GetMetatagsXml']/@Description" />

Then - check "Preview" to be sure that you're receiving the right output, press "Save" and go back to the page layout.

 

Inside layout you can either write function call markup by yourself or press "Add function" button on top. The result markup in the page layout will look like:

<f:function xmlns:f="http://www.composite.net/ns/function/1.0" name="Volleyball.Meta.Metatags.GetMetatagsXml">

Oct 28, 2010 at 8:43 PM

Hi Napernik,

Thank you for clarifying.

I thought the Page template was an XSLT file, but now that i know it's not, it makes a lot more sense to me :-)

The function system works perfectly, i just thought i could skip it some how.

Regards

 Martin