Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ste 5 posts 11 karma points
    Aug 12, 2013 @ 13:40
    Ste
    0

    XML tag appears when adding macro between <title> tags.

    Good afternoon.

    I've got a simple macro that renders a generic property to the browser. If I add this to the body of the page, my string appears as expected. "Company Name", for example.

    However, if I add this to the title tags I get:

    ?xml version="1.0" encoding="utf-16"?>Company Name

    I can't think why this would be happening, especially as it's only when it's between the title tags. The Xslt isn't complex:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
      <!ENTITY nbsp "&#x00A0;">
    ]>
    <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" indent="no"/>
    
      <xsl:template match="@* | node()">
        <xsl:variable name="homeNode" select="umbraco.library:GetXmlNodeById(1065)"/>
    
        <xsl:value-of select="$homeNode/siteName"/>
      </xsl:template>
    </xsl:stylesheet>
    

    Thanks in advance for any advice.

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Aug 13, 2013 @ 10:41
    Chriztian Steinmeier
    0

    Hi Ste,

    I assume if you view source you'll see the same code output - but XML/HTML tags aren't allowed between the <title> tags, so the browser will do some filtering to make sure it doesn't explode.

    You should do two things to the above macro:

    1. Change the match attribute to match="/"
    2. Add the omit-xml-declaration="yes" attribute to the <xsl:output> element, which will make sure not to output anything but the value you specify

    Like this:

    <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" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:template match="/">
            <xsl:variable name="homeNode" select="umbraco.library:GetXmlNodeById(1065)"/>
            <xsl:value-of select="$homeNode/siteName"/>
        </xsl:template>
    
    </xsl:stylesheet>
    

    You could actually also change the method="xml" to method="text", since you're only rendering a textfield - but who knows what you'll do later, right?

    /Chriztian

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies