Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternate XML output? #16

Open
jonnio opened this issue Dec 19, 2019 · 2 comments
Open

Alternate XML output? #16

jonnio opened this issue Dec 19, 2019 · 2 comments

Comments

@jonnio
Copy link

jonnio commented Dec 19, 2019

More of a comment about a potential extension. We load the output into a document database and use XPath to access the data. As the elements have an @Id attribute in them, the XPaths get a bit ugly. To that end, we run the output through the following XSLT which moves the @Id into the element name (when a segment or element). It would be fantastic if element naming was an option so we could stop using the XSLT.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="no"/>
    <xsl:strip-space elements="*"/>

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

    <xsl:template match="segment[@Id]">
        <xsl:element name="{normalize-space(@Id)}">
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>

    <xsl:template match="element[@Id]">
        <xsl:element name="{normalize-space(@Id)}">
            <xsl:value-of select="."/>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>
@canabrook
Copy link
Contributor

canabrook commented Dec 19, 2019 via email

@jonnio
Copy link
Author

jonnio commented Jan 2, 2020

Just the "Id" attribute is needed because this establishes more direct XPath expressions. The other attributes really are data attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants