S
Simon Brooke
The designers of the iPhone browser, for reasons of their own, chose not
to honour the 'media="handheld"' attribute of style sheet links (and the
designers of the Android browser have slavishly followed the iPhone in
this, to my mind, poor decision). Consequently you have to use obscure
and nasty hacks with media queries in order to get iPhone and Android to
select the right style sheet:
<link rel="stylesheet" href="/scenehere/styles/handheld.css"
type="text/css">
<xsl:attribute name="media">
<xsl:value-of
select="normalize-space( concat('only screen and (max-device-width:
', $switch-width - 1, 'px)'))" />
</xsl:attribute>
</link>
<!-- tell iPhone not to shrink mobile website -->
<meta name="viewport"
content="width=320; initial-scale=1.0; maximum-scale=1.0;
user-scalable=0;" />
Unfortunately, all versions of Internet Explorer up to and including the
latest beta of Internet Explorer 9 throw a paddy when they see the media
query and refuse to load any style sheet at all.
There's a workaround, documented here:
http://www.iphonemicrosites.com/tutorials/using-media-query-to-declare-
css-for-iphone/
which is that you surround the bits that Internet Explorer can't parse
with proprietary markup:
<!--[if !IE]>-->
<link type="text/css" rel="stylesheet" media="only screen and (max-device-
width: 480px)" href="iPhone.css">
<!--<![endif]-->
I've tried three different methods of generating this markup with XSL.
Putting it in a <![CDATA[ ]]> fails because it ends up generating
<,> instead of <,>. Enclosing it in <xsl:comment></xsl:comment>
fails because in the proprietary markup the *lack* of whitespace after
the double hyphen is significant! Marking it all up using character
entities in place of angle brackets works perfectly with xsltproc
1.1.24-2; however, what I'm using on my production system is Xalan (Java)
2.7.1-2, and it stops processing when it encounters this markup.
I'm not actually sure whether the behaviour of xsltproc or the behaviour
of Xalan is correct. The proprietary markup required by Internet Explorer
is (probably deliberately) not well formed, so it isn't surprising that
it's very difficult to generate.
Does anyone have a solution, or suggestions of some further avenues I
might explore?
to honour the 'media="handheld"' attribute of style sheet links (and the
designers of the Android browser have slavishly followed the iPhone in
this, to my mind, poor decision). Consequently you have to use obscure
and nasty hacks with media queries in order to get iPhone and Android to
select the right style sheet:
<link rel="stylesheet" href="/scenehere/styles/handheld.css"
type="text/css">
<xsl:attribute name="media">
<xsl:value-of
select="normalize-space( concat('only screen and (max-device-width:
', $switch-width - 1, 'px)'))" />
</xsl:attribute>
</link>
<!-- tell iPhone not to shrink mobile website -->
<meta name="viewport"
content="width=320; initial-scale=1.0; maximum-scale=1.0;
user-scalable=0;" />
Unfortunately, all versions of Internet Explorer up to and including the
latest beta of Internet Explorer 9 throw a paddy when they see the media
query and refuse to load any style sheet at all.
There's a workaround, documented here:
http://www.iphonemicrosites.com/tutorials/using-media-query-to-declare-
css-for-iphone/
which is that you surround the bits that Internet Explorer can't parse
with proprietary markup:
<!--[if !IE]>-->
<link type="text/css" rel="stylesheet" media="only screen and (max-device-
width: 480px)" href="iPhone.css">
<!--<![endif]-->
I've tried three different methods of generating this markup with XSL.
Putting it in a <![CDATA[ ]]> fails because it ends up generating
<,> instead of <,>. Enclosing it in <xsl:comment></xsl:comment>
fails because in the proprietary markup the *lack* of whitespace after
the double hyphen is significant! Marking it all up using character
entities in place of angle brackets works perfectly with xsltproc
1.1.24-2; however, what I'm using on my production system is Xalan (Java)
2.7.1-2, and it stops processing when it encounters this markup.
I'm not actually sure whether the behaviour of xsltproc or the behaviour
of Xalan is correct. The proprietary markup required by Internet Explorer
is (probably deliberately) not well formed, so it isn't surprising that
it's very difficult to generate.
Does anyone have a solution, or suggestions of some further avenues I
might explore?