adding a custom title field into the document template
Hi There,
I have a macro that renders Keywords and descriptions on my template. I want to know if I can add a title tag into it as well, but I'm unsure of the syntax. Can someone help me with the XSLT and the XPATH for this please?
Go to your xslt file in the Developer section of umbraco and click the "visualise xslt" button. Choose a page on your site where you have entered the title fields etc. Does the visualisation give the expected output? If there are problems with the xslt, you will get an error with more detail here.
Here is the output from the visual. What am I missing?
Error parsing the XSLT:
System.Xml.Xsl.XslLoadException:
XSLT compile error. An error occurred at (3,3). --->
System.Xml.XmlException: Expected DTD markup was not found. Line 3,
position 3.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at
System.Xml.XmlTextReaderImpl.DtdParserProxy.System.Xml.IDtdParserAdapter.Throw(Exception
e)
at System.Xml.DtdParser.Throw(Int32 curPos, String res, String arg)
at System.Xml.DtdParser.ScanSubsetContent()
at System.Xml.DtdParser.GetToken(Boolean needWhiteSpace)
at System.Xml.DtdParser.ParseSubset()
at System.Xml.DtdParser.ParseInDocumentDtd(Boolean
saveInternalSubset)
at System.Xml.DtdParser.Parse(Boolean saveInternalSubset)
at
System.Xml.DtdParser.System.Xml.IDtdParser.ParseInternalDtd(IDtdParserAdapter
adapter, Boolean saveInternalSubset)
at System.Xml.XmlTextReaderImpl.ParseDtd()
at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.Xsl.Xslt.XsltInput.ReadTextNodes()
at System.Xml.Xsl.Xslt.XsltInput.ReadNextSibling()
at System.Xml.Xsl.Xslt.XsltInput.FindStylesheetElement()
at System.Xml.Xsl.Xslt.XsltLoader.LoadDocument()
at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader,
Boolean include)
--- End of inner exception stack trace ---
at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader,
Boolean include)
at System.Xml.Xsl.Xslt.XsltLoader.Load(XmlReader reader)
at System.Xml.Xsl.Xslt.XsltLoader.Load(Compiler compiler, Object
stylesheet, XmlResolver xmlResolver)
at System.Xml.Xsl.Xslt.Compiler.Compile(Object stylesheet,
XmlResolver xmlResolver, QilExpression& qil)
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object
stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at umbraco.macro.CreateXsltTransform(XmlTextReader xslReader, Boolean
debugMode)
at
umbraco.presentation.umbraco.developer.Xslt.xsltVisualize.visualizeDo_Click(Object
sender, EventArgs e)
Thanks very much for the help. I played around with the code, taking all suggestions on ob board. I finally got it to work after having a little trouble with the title.
Just a quick note: you could consider using the $title instead of $currentPage/title in the title-element, or just skip the creation of the title-variable. It's just a small thing, but just wanted to let you know :)
adding a custom title field into the document template
Hi There,
I have a macro that renders Keywords and descriptions on my template. I want to know if I can add a title tag into it as well, but I'm unsure of the syntax. Can someone help me with the XSLT and the XPATH for this please?
I'm using:
unbraco 4.6, windows 2008 & .net 4.0.
Thanks in advance for your answer
Sean
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="title" select="/macro/title"/>
<xsl:variable name="keywords" select="/macro/keywords"/>
<xsl:variable name="description" select="/macro/description"/>
<xsl:template match="/">
<title><xsl:value-of select="{$title}"/></title>
<meta name="keywords" content="{$keywords}" />
<meta name="description" content="{$description}" />
</xsl:template>
</xsl:stylesheet>
<umbraco:Item field="metaDescription" insertTextBefore="<meta name="description" content="" insertTextAfter="" />" runat="server"></umbraco:Item>
<umbraco:Item field="metaKeywords" insertTextBefore="<meta name="keywords" content="" insertTextAfter="" />" runat="server"></umbraco:Item>
Your code looks perfect.
But I don't understand why you posted two differtent solutions (xslt and page fields).
Hi Sean
Have you inserted the XSLT macro inside the head-section of your page? Or are you using the umbraco:Item's to render the meta-tags?
This part:
should wotk if you have inserted the macro inside the template.
But this part:
would only generate the description and keywords meta-tags if you insert these in the template.
/Kim A
Hi All,
Using the XSLT macro above.
Now I get the error below:
Any ideas what i'm missing?
Sean
Hi Sean,
Go to your xslt file in the Developer section of umbraco and click the "visualise xslt" button. Choose a page on your site where you have entered the title fields etc. Does the visualisation give the expected output? If there are problems with the xslt, you will get an error with more detail here.
Hi Lesley,
Here is the output from the visual. What am I missing?
Error parsing the XSLT:
System.Xml.Xsl.XslLoadException: XSLT compile error. An error occurred at (3,3). ---> System.Xml.XmlException: Expected DTD markup was not found. Line 3, position 3. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.DtdParserProxy.System.Xml.IDtdParserAdapter.Throw(Exception e) at System.Xml.DtdParser.Throw(Int32 curPos, String res, String arg) at System.Xml.DtdParser.ScanSubsetContent() at System.Xml.DtdParser.GetToken(Boolean needWhiteSpace) at System.Xml.DtdParser.ParseSubset() at System.Xml.DtdParser.ParseInDocumentDtd(Boolean saveInternalSubset) at System.Xml.DtdParser.Parse(Boolean saveInternalSubset) at System.Xml.DtdParser.System.Xml.IDtdParser.ParseInternalDtd(IDtdParserAdapter adapter, Boolean saveInternalSubset) at System.Xml.XmlTextReaderImpl.ParseDtd() at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl() at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlTextReader.Read() at System.Xml.Xsl.Xslt.XsltInput.ReadTextNodes() at System.Xml.Xsl.Xslt.XsltInput.ReadNextSibling() at System.Xml.Xsl.Xslt.XsltInput.FindStylesheetElement() at System.Xml.Xsl.Xslt.XsltLoader.LoadDocument() at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include) --- End of inner exception stack trace --- at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include) at System.Xml.Xsl.Xslt.XsltLoader.Load(XmlReader reader) at System.Xml.Xsl.Xslt.XsltLoader.Load(Compiler compiler, Object stylesheet, XmlResolver xmlResolver) at System.Xml.Xsl.Xslt.Compiler.Compile(Object stylesheet, XmlResolver xmlResolver, QilExpression& qil) at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) at umbraco.macro.CreateXsltTransform(XmlTextReader xslReader, Boolean debugMode) at umbraco.presentation.umbraco.developer.Xslt.xsltVisualize.visualizeDo_Click(Object sender, EventArgs e)
Sean,
Can you check line 2. Do you really have
or perhaps it should be
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
(Note the <)
Hi again Sean.
I'd check the thing that Lesley mentioned as well, to see if the error disappears.
Beside that, if you have created three fields on your document types for each of the three meta tags, then you should probably change this code:
to something like this:
/Kim A
Hi Guys,
Thanks very much for the help. I played around with the code, taking all suggestions on ob board. I finally got it to work after having a little trouble with the title.
I Appreciate your help.
Sean
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="title" select="$currentPage/title"/>
<xsl:variable name="keywords" select="$currentPage/keywords"/>
<xsl:variable name="description" select="$currentPage/description"/>
<xsl:variable name="googlekey" select="$currentPage/googlekey"/>
<xsl:template match="/">
<title><xsl:value-of select="$currentPage/title"/></title>
<meta name="keywords" content="{$keywords}" />
<meta name="description" content="{$description}" />
<meta name="verify-v1" content="{$googlekey}" />
</xsl:template>
</xsl:stylesheet>
Great to hear Sean.
Just a quick note: you could consider using the $title instead of $currentPage/title in the title-element, or just skip the creation of the title-variable. It's just a small thing, but just wanted to let you know :)
/Kim A
is working on a reply...