10

I'm trying to add a tag like

<div itemscope>

in my xslt transformation but I get an error.(The expected token is '=')

I'm working in C# .net 4.0 xslt 1.0.

Christophe Debove
  • 6,088
  • 20
  • 73
  • 124

2 Answers2

20

XSLT is optimized for generating XML output. HTML5 is, in general, not XML. The syntax

<div itemscope>

is clearly not XML and therefore can't be generated using xsl:attribute. This is because XML doesn't support empty-valued attributes. That's the bad news.

The good news: There are two ways of writing the same thing as <div itemscope> that are valid HTML5 and valid XML:

<div itemscope="">
<div itemscope="itemscope">

So pick your favorite and generate that!

cygri
  • 9,412
  • 1
  • 25
  • 47
  • 1
    This is correct +1. The fact that _HTML_ allows non-XML rules like attribute without values or attribute values without quotes does not mean that you MUST use them. When dealing with XSLT (I think even in other cases) you MUST use the corresponding markup alternatives specified in the W3C spec. – Emiliano Poggi Jun 23 '11 at 13:04
  • do you know if itemscope="itemscope" respond to my microdata problematic describe at : http://schema.org/Place ? – Christophe Debove Jun 23 '11 at 13:39
  • 1
    @Christophe: I'm afraid I don't quite understand the question. I'll repeat: `
    ` is equivalent to `
    ` and equivalent to `
    `.
    – cygri Jun 23 '11 at 22:16
  • 1
    @Tomalak: No, you can't give it any value you like. `itemscope` is an HTML5 boolean attribute. This means the only allowed values are no value (`
    `), the empty string (`
    `), and the name of the attribute itself (`
    `). Any other value is invalid HTML5.
    – cygri Jun 23 '11 at 22:19
  • The HTML serialization of HTML5 is not XML, but HTML5 has an alternative serialization as XML document: XHTML5. This laureate standard serialization is defined in the HTML5 specification. If you serve your document as XHTML5, you can benefit from the XML toolings like XSLT as well as using HTML5 standards like microdata. – Lie Ryan Jul 22 '15 at 22:22
  • when I use `itemscope` in blogger.com, the editor changes `itemscope` to `itemscope=""` after I switch from HTML edit mode. – noobninja Aug 29 '15 at 16:22
1
<xsl:text disable-output-escaping="yes"><![CDATA[<div itemscope>]]></xsl:text>
Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125