help needed to output a comma separated ASCII file from an incoming xml file using xslt. Below Listed are the input and output. I am struck on defining the template to read each character from the input xml file. Any help is highly appreciated...

INPUT:

<DST xml:lang="en-US">
<jobName version="1.0">SRVAuthenticate</jobName>
<trace>0</trace>
<readable>N</readable>
<AWD>
<userID>PLATFRM1</userID>
<password>12345679</password>
<newPassword></newPassword>
</AWD>
</DST>

OUTPUT:


[60, 68, 83, 84, 32, 120, 109, 108, 58, 108, 97, 110, 103, 61, 34, 101, 110, 45, 85, 83, 34, 62, 13, 10, 32, 32, 32, 32, 60, 106, 111, 98, 78, 97, 109, 101, 32, 118, 101, 114, 115, 105, 111, 110, 61, 34, 49, 46, 48, 34, 62, 83, 82, 86, 65, 117, 116, 104, 101, 110, 116, 105, 99, 97, 116, 101, 60, 47, 106, 111, 98, 78, 97, 109, 101, 62, 13, 10, 32, 32, 32, 32, 60, 116, 114, 97, 99, 101, 62, 48, 60, 47, 116, 114, 97, 99, 101, 62, 13, 10, 32, 32, 32, 32, 60, 114, 101, 97, 100, 97, 98, 108, 101, 62, 78, 60, 47, 114, 101, 97, 100, 97, 98, 108, 101, 62, 13, 10, 32, 32, 32, 32, 60, 65, 87, 68, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 117, 115, 101, 114, 73, 68, 62, 80, 76, 65, 84, 70, 82, 77, 49, 60, 47, 117, 115, 101, 114, 73, 68, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 112, 97, 115, 115, 119, 111, 114, 100, 62, 49, 50, 51, 52, 53, 54, 55, 57, 60, 47, 112, 97, 115, 115, 119, 111, 114, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 110, 101, 119, 80, 97, 115, 115, 119, 111, 114, 100, 62, 60, 47, 110, 101, 119, 80, 97, 115, 115, 119, 111, 114, 100, 62, 13, 10, 32, 32, 32, 32, 60, 47, 65, 87, 68, 62, 13, 10, 60, 47, 68, 83, 84, 62, 13, 10, 13, 10, 13, 10]

Dani AI

Generated

is right that XSLT is a bit heavy for byte/character-level work. Two practical approaches are recommended given 's sample output (which is the serialized XML turned into numeric character codes): (A) an XSLT-based solution that serializes the document and converts characters to codepoints (requires XSLT 3.0 or processor extensions), or (B) a tiny binary-read script (Python/Perl) that emits the file bytes — simpler and more robust for exact ASCII/byte output.

A compact XSLT 3.0 approach (serialize -> string-to-codepoints -> join) looks like this:

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization">
  <xsl:output method="text"/>
  <xsl:template match="/">
    <xsl:variable name="params">
      <output:serialization-parameters>
        <output:omit-xml-declaration>yes</output:omit-xml-declaration>
        <output:indent>yes</output:indent>
      </output:serialization-parameters>
    </xsl:variable>
    <xsl:variable name="s" select="serialize(/, $params/*)"/>
    <xsl:variable name="codes" select="string-to-codepoints($s)"/>
    <xsl:text>[</xsl:text>
    <xsl:value-of select="string-join($codes, ', ')" />
    <xsl:text>]</xsl:text>
  </xsl:template>
</xsl:stylesheet>

This serializes the node tree and converts the resulting characters to Unicode codepoints for joining. (w3.org)

A much simpler alternative is a one‑liner that reads the file as binary and prints each byte (this ensures exact octet values including CR=13/LF=10):

python3 -c "b=open('in.xml','rb').read(); print('[' + ', '.join(str(x) for x in b) + ']')"

Note the distinction: XSLT functions produce Unicode codepoints from the serialized string; many processors return a string (not raw octets), so encoding/serialization settings can affect the visible characters but not the in-memory string representation — that can cause subtle mismatches. (saxonica.com)

Troubleshooting tips: match serializer settings (omit-xml-declaration, indent) and force line endings if needed (some engines offer a newline/CRLF parameter; Saxon documents a saxon:newline serialization option). If portability and exact-bytes matter, prefer the binary-script route; if an XSLT solution is required, use XSLT 3.0 or a processor extension (Saxon) rather than XSLT 1.0. (saxonica.com)

Is there a reason you want to do this using an XSLT ? I don't think it is a wise choice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.