Search code examples
xmlxsltdelimiterapostrophe

xslt: Generate xml attribute value with single quotation (apostrophe) as delimiter


xslt processing seems always to generate attribute values with double quotation marks as delimiter.
Input xml:

<a b='"c"' />  

Output xml:

<a b="&quot;c&quot;"/>

I have to generate XML files with apostrophe as attribute value delimiter for a phone device. This device only accept attribute values with apostrophe and double quotation marks as delimiter. E.g.:

<SYMB_ITEM ID="BS_Accounts.astAccounts[0].aucAccountName[0]"
class="symb_item" value='"test_3"'/>  

Is it possible to keep apostrophe as delimiter for attribute values with xslt (xlstproc)?


Solution

  • I'm not sure if I understand your question correctly: would setting output to "text" help?

    <xsl:output method="text" encoding="utf-8" indent="no"/>
    

    Example XSLT sheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
      <xsl:output method="text" encoding="utf-8" indent="no"/>
    
      <xsl:template match="/">
        <xsl:apply-templates />
      </xsl:template>
    
      <xsl:template match="a">
        &lt;a b='<xsl:value-of select="@b"/>'&gt;
      </xsl:template>                      
    </xsl:stylesheet>
    

    For following XML file:

    <xml>
      <a b='"c"' />   
      <a b='"x"' />
    </xml>
    

    Produces (as I think) desired effect:

    <a b='"c"'>
    <a b='"x"'>