XML/Input: Difference between revisions

Content added Content deleted
m (Alphabetizing, highlighting)
(→‎{{header|J}}: noted that XPath is implicitly discouraged as a soln, for some reason, so use SAX instead.)
Line 46: Line 46:


=={{header|J}}==
=={{header|J}}==
J's system includes XML processing libraries -- this task is best addressed with the XSLT library:
J's system includes several XML processing libraries. This task is probably best addressed using XPath (this is the type of problem XPath was designed to solve), but the task description implicitly discourages that method. So we can use the SAX library instead:


load 'xml/xslt'
load'xml/sax'
saxclass 'Students'
XSL xslt XML
startElement =: ([: smoutput 'Name' getAttribute~ [)^:('Student'-:])
cocurrent'base'
process_Students_ XML
April
April
Bob
Bob
Line 57: Line 61:
Emily
Emily


with the appropriate definitions of <tt>XSL</tt> and <tt>XML</tt>:
and the definition of <tt>XML</tt>:
XML =: noun define
XML =: noun define
<Students>
<Students>
Line 67: Line 70:
<Student Name="Emily" />
<Student Name="Emily" />
</Students>
</Students>
)
XSL =: noun define
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:h="http://www.w3.org/1999/xhtml">
<xsl:output method="text" encoding="UTF-8" media-type="text/plain" />
<xsl:template match="/">
<xsl:apply-templates select="/Students/Student" />
</xsl:template>
<xsl:template match="/Students/Student">
<xsl:value-of select="@Name" />
<!-- Platform-independent line breaks (instead of &#10; or something) -->
<xsl:text><![CDATA[
]]></xsl:text>
</xsl:template>
</xsl:stylesheet>
)
)