Re: [xsl] <option selected> breaking xsl?

Subject: Re: [xsl] <option selected> breaking xsl?
From: Syd Bauman <Syd_Bauman@xxxxxxxxx>
Date: Thu, 6 Oct 2011 22:52:49 -0400
"<option selected>" is not a valid tag in XML. In *HTML* that tag
indicates the start of an <option> element whose selected= attribute
has the value "selected". But XML does not permit attribute names to
be omitted, even when the name is unambiguously derivalbe from the
value. 

So you'd have to express this as 

| <option selected="selected"><xsl:value-of select="position()" /></option>

The reason, BTW, that this is "breaking" the stylesheet is that
"<option selected>" is not even well-formed XML. So whether it is in
the XSL namespace or not, it means that your stylesheet is not
well-formed XML, and therefore the XSL engine can't even start to
read it. Notice that the unhelpful error message you got was issued
from the XML parser.

> i'm creating a dropdown that is populated by page numbers
> determined by xsl and a number of items per page. i've got the
> dropdown working with the js and xsl, but now i'm trying to have
> the *current* page be the one that displays when the dropdown is
> created (so if i'm on page 4, "4" is the pre-selected option in the
> dropdown.
> 
> i know the attribute in html is <option selected> -- but it causes
> an xsl transform error every time. i know this, because i've taken
> just that one attribute out of my code, and the code doesn't break.
> 
> <code>
> <!-- dropdown page menu -->      	
> 								<select id="pageMenu" onChange="turnPage();">
> 									<xsl:for-each select="//PageOffset">
> 										<xsl:choose>
> 											<xsl:when test=". != ../CurrentItemOffset">
> 												<option><xsl:value-of select="position()"/></option>
> 											</xsl:when>
> 											<xsl:otherwise>
> 												<option selected><xsl:value-of select="position()" /></ 
> option>
> 											</xsl:otherwise>
> 										</xsl:choose>
> 									</xsl:for-each>
> 								</select>	
> </code>
> 
> If i take out the 'selected' attribute in the <xsl:otherwise>
> clause, the page loads normally. Obviously, the choose block is
> pointless if i do that, though!
> 
> i'm positing that the transform is choking on the 'selected'
> because it looks like the 'select' attribute in xsl - but it's not
> in an xsl tag, so why?
> 
> Of course, just like last time, the error message is not helpful:
> <blockquote> XSL Transform Error: java.lang.Exception:
> org.xml.sax.SAXParseException: character not allowed
> Message:org.xml.sax.SAXParseException: character not allowed
> </blockquote>
> 
> can anyone tell me why 'selected' is breaking the page, and if
> there's a way to do this?

Current Thread