xsl-list
[Top] [All Lists]

[xsl] Re: Initial whitespace in PI from XSLT, appendices

2022-05-07 16:34:12
APPENDIX A: XSLT program and input document
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="1.0">

  <?syd nospace?>
  <?syd already normalized space?>
  <?syd lots of     space    between  stuff   ?>
  <?syd     leading spaces      and     tabs    between!?>
  <?syd let’s try a new
    line ?>
  <?syd
    leading newline?>

  <xsl:template match="/">
    <anOutermostElement>
      <xsl:text>&#x0A;</xsl:text>
      <xsl:apply-templates select="//processing-instruction()"/>
    </anOutermostElement>
  </xsl:template>

  <xsl:template match="processing-instruction()">
    <!-- Announce that we are processing the next PI: -->
    <xsl:text>--------- first 3 chars=</xsl:text>
    <xsl:value-of select="concat('‘', substring( ., 1, 3 ), '’')"/>

    <!-- Try copying to output: -->
    <xsl:text>&#x0A;     copy: </xsl:text>
    <xsl:copy/>

    <!-- I expect this different way of expressing "copy this" to do the same 
thing: -->
    <xsl:text>&#x0A;  copy-of: </xsl:text>
    <xsl:copy-of select="."/>

    <!-- Construct a new processing instruction based on the input: -->
    <xsl:text>&#x0A; proc-ins: </xsl:text>
    <xsl:processing-instruction name="{name(.)}">
      <xsl:value-of select="."/>
    </xsl:processing-instruction>

    <!-- Construct, but normalize space on the value string first: -->
    <xsl:text>&#x0A; norm-spc: </xsl:text>
    <xsl:processing-instruction name="{name(.)}">
      <xsl:value-of select="normalize-space(.)"/>
    </xsl:processing-instruction>

    <!-- Construct, but (try to) force a space as 1st char: -->
    <xsl:text>&#x0A;insrt-spc: </xsl:text>
    <xsl:processing-instruction name="{name(.)}">
      <xsl:value-of select="concat(' ', normalize-space(.) )"/>
    </xsl:processing-instruction>

    <!-- Construct, but (try to) force a newline as 1st char: -->
    <xsl:text>&#x0A;insrt-nln: </xsl:text>
    <xsl:processing-instruction name="{name(.)}">
      <xsl:value-of select="concat('&#x0A;', normalize-space(.) )"/>
    </xsl:processing-instruction>

    <xsl:text>&#x0A;</xsl:text>
  </xsl:template>

</xsl:stylesheet>

APPENDIX B: Output from `xsltproc`
<?xml version="1.0"?>
<anOutermostElement>
--------- first 3 chars=‘nos’
     copy: <?syd nospace?>
  copy-of: <?syd nospace?>
 proc-ins: <?syd nospace?>
 norm-spc: <?syd nospace?>
insrt-spc: <?syd  nospace?>
insrt-nln: <?syd
nospace?>
--------- first 3 chars=‘alr’
     copy: <?syd already normalized space?>
  copy-of: <?syd already normalized space?>
 proc-ins: <?syd already normalized space?>
 norm-spc: <?syd already normalized space?>
insrt-spc: <?syd  already normalized space?>
insrt-nln: <?syd
already normalized space?>
--------- first 3 chars=‘lot’
     copy: <?syd lots of     space    between  stuff   ?>
  copy-of: <?syd lots of     space    between  stuff   ?>
 proc-ins: <?syd lots of     space    between  stuff   ?>
 norm-spc: <?syd lots of space between stuff?>
insrt-spc: <?syd  lots of space between stuff?>
insrt-nln: <?syd
lots of space between stuff?>
--------- first 3 chars=‘lea’
     copy: <?syd leading spaces and     tabs    between!?>
  copy-of: <?syd leading spaces and     tabs    between!?>
 proc-ins: <?syd leading spaces and     tabs    between!?>
 norm-spc: <?syd leading spaces and tabs between!?>
insrt-spc: <?syd  leading spaces and tabs between!?>
insrt-nln: <?syd
leading spaces and tabs between!?>
--------- first 3 chars=‘let’
     copy: <?syd let’s try a new
    line ?>
  copy-of: <?syd let’s try a new
    line ?>
 proc-ins: <?syd let’s try a new
    line ?>
 norm-spc: <?syd let’s try a new line?>
insrt-spc: <?syd  let’s try a new line?>
insrt-nln: <?syd
let’s try a new line?>
--------- first 3 chars=‘lea’
     copy: <?syd leading newline?>
  copy-of: <?syd leading newline?>
 proc-ins: <?syd leading newline?>
 norm-spc: <?syd leading newline?>
insrt-spc: <?syd  leading newline?>
insrt-nln: <?syd
leading newline?>
</anOutermostElement>

APPENDIX C: Output from Saxon:
<?xml version="1.0" encoding="UTF-8"?><anOutermostElement>
--------- first 3 chars=‘nos’
     copy: <?syd nospace?>
  copy-of: <?syd nospace?>
 proc-ins: <?syd nospace?>
 norm-spc: <?syd nospace?>
insrt-spc: <?syd nospace?>
insrt-nln: <?syd nospace?>
--------- first 3 chars=‘alr’
     copy: <?syd already normalized space?>
  copy-of: <?syd already normalized space?>
 proc-ins: <?syd already normalized space?>
 norm-spc: <?syd already normalized space?>
insrt-spc: <?syd already normalized space?>
insrt-nln: <?syd already normalized space?>
--------- first 3 chars=‘lot’
     copy: <?syd lots of     space    between  stuff   ?>
  copy-of: <?syd lots of     space    between  stuff   ?>
 proc-ins: <?syd lots of     space    between  stuff   ?>
 norm-spc: <?syd lots of space between stuff?>
insrt-spc: <?syd lots of space between stuff?>
insrt-nln: <?syd lots of space between stuff?>
--------- first 3 chars=‘lea’
     copy: <?syd leading spaces and     tabs    between!?>
  copy-of: <?syd leading spaces and     tabs    between!?>
 proc-ins: <?syd leading spaces and     tabs    between!?>
 norm-spc: <?syd leading spaces and tabs between!?>
insrt-spc: <?syd leading spaces and tabs between!?>
insrt-nln: <?syd leading spaces and tabs between!?>
--------- first 3 chars=‘let’
     copy: <?syd let’s try a new
    line ?>
  copy-of: <?syd let’s try a new
    line ?>
 proc-ins: <?syd let’s try a new
    line ?>
 norm-spc: <?syd let’s try a new line?>
insrt-spc: <?syd let’s try a new line?>
insrt-nln: <?syd let’s try a new line?>
--------- first 3 chars=‘lea’
     copy: <?syd leading newline?>
  copy-of: <?syd leading newline?>
 proc-ins: <?syd leading newline?>
 norm-spc: <?syd leading newline?>
insrt-spc: <?syd leading newline?>
insrt-nln: <?syd leading newline?>
</anOutermostElement>
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>