Page 1 of 1
Conditional Character map?
Posted: Thu Apr 14, 2011 1:38 am
by sderrick
I need to generate output for different media targets from the same xml source.
One of the targets is mobi pocket for the Kindle, with 1980's era markup capability. I have 10-15 unicode characters in the xml, like en-dashes, em-dashes, thin spaces, etc. that the kindle doesn't have support for in it's font set.
I would like to be able to conditionally use a character map in the same xsl script, that would leave the characters alone for html or epub, but replace them if generating for the Kindle.
Is this possible?
thanks,
Scott
Re: Conditional Character map?
Posted: Thu Apr 14, 2011 4:58 pm
by adrian
Hello,
xsl:character-map allows a "use-when" attribute(
Conditional Element Inclusion) but unfortunately its value is evaluated statically so you can't use a parameter or variable to trigger it.
Regards,
Adrian
Replace unicode with html entitys; was
Posted: Sun Apr 17, 2011 7:21 pm
by sderrick
Instead of using character-map I am trying to use the translate function.
Using this works well
translate(.,"-,'-')
but this fails
translate(.,'®,'®')
with
F [Saxon-HE 9.3.0.4] The entity "reg" was not declared, but was referenced in the attribute "select" of the element "xsl:value-of".
How can I get the translate function to output ® if it sees ®?
Scott
Re: Conditional Character map?
Posted: Sun Apr 17, 2011 8:56 pm
by sderrick
Hmmm...
Using translate() is going so well..
I tried declaring this
<!DOCTYPE stylesheet [
<!ENTITY reg
"<xsl:text disable-output-escaping='yes'> '®' </xsl:text>">
]>
To allow me to use the ® entity, but that causes another error at the point of the ® ..
F [Saxon-HE 9.3.0.4] The value of attribute "select" associated with an element type "xsl:value-of" must not contain the '<' character.
?????
Re: Conditional Character map?
Posted: Mon Apr 18, 2011 11:18 am
by adrian
Hello,
If you want to use the translate function you need a 1 to 1 mapping of the characters in the second and third argument strings(1 character in the second argument is replaced with the corresponding character from the third argument). But if I understand correctly you want to replace a character with an entity(1 to many): ® -> ® so you're going to have to use the replace function instead.
e.g.
Code: Select all
<xsl:value-of select="replace(.,'®','®')" disable-output-escaping="yes"/>
PS: If you declare an entity and use an XML/XSL snippet as its value, when the stylesheet is compiled the parser will substitute the entity reference with its value so you will obtain an invalid stylesheet(an xml:text element inside the value of the select attribute. Hence the error...
Regards,
Adrian
Re: Conditional Character map?
Posted: Mon Apr 18, 2011 4:15 pm
by sderrick
I bailed on the utility of having it in a single stylesheet and went with a kludge of having my character-maps in separate style sheets.
Not a neat and tidy as I'm used to when coding in a real programming language but it does work.
thanks for all the input.
Scott