0

I have a stylesheet that processes stylesheets

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="xsl:value-of">
    <xsl:copy>
      <xsl:copy-of select="@*[name() != 'select']"/>
      <xsl:if test="@select">
        <xsl:attribute name="select">
          <xsl:text>concat('[', "</xsl:text>
          <xsl:value-of select="@select" />
          <xsl:text>", ']')</xsl:text>
        </xsl:attribute>
      </xsl:if>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

and need to to be able to accept any arbitrary combination/sequence of quotes in the select attribute and still produce a correct result.

As a, trivial, example

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:template match="/">
    <xsl:value-of select="concat('Style', &quot;sheet&quot;)"/>
  </xsl:template>
</xsl:stylesheet>

is not processed correctly.

There are numerous questions about specific cases:

but these do not address the general problem. I realise that a recursive function that parsed all the offending characters and replaced them with variable references to constant values could be used, but this would require wrapping the entire string in a concat() function that would make the resulting code even more unreadable.

While the XSL 2.0 replace() function and doubling up would solve this quite straightforwardly, there does not appear to be a 1.0 solution for this.

Current output is

<xsl:stylesheet version="1.0" exclude-result-prefixes="msxsl"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:msxsl="urn:schemas-microsoft-com:xslt">
  <xsl:template match="/">
    <xsl:value-of select="concat('[', &quot;concat('Style', &quot;sheet&quot;)&quot;, ']')" />
  </xsl:template>
</xsl:stylesheet>

but will not validate as shown.

Community
  • 1
  • 1
Pekka
  • 3,529
  • 27
  • 45
  • Could you explain what are you trying to accomplish here and show the expected result of the transformation? – michael.hor257k Jul 19 '16 at 20:30
  • I have no specific expected output, just content that is valid XSL/XPATH. – Pekka Jul 20 '16 at 08:32
  • Huh? If you have no expected output, then what's the purpose of transforming the input? – michael.hor257k Jul 20 '16 at 11:03
  • 'no specific expected output' does not mean 'no expected output'. What I am saying is that I do not have any preference on what the output should look like. For completeness I have provided the output generated by the provided stylesheet. – Pekka Jul 20 '16 at 11:34
  • 1
    What I am saying is that I don't understand what you're trying to do. So I have no way to asses any suggested method as successful or not. – michael.hor257k Jul 20 '16 at 11:48
  • I am trying to see if it is possible to use XSL to process stylesheets for various documentation and quality analyses. The current applications is to generate enough information in the output to reliably identify the source of each output fragment by localised inspection. – Pekka Jul 20 '16 at 11:57

0 Answers0