edireader icon indicating copy to clipboard operation
edireader copied to clipboard

Alternate XML output?

Open jonnio opened this issue 5 years ago • 2 comments

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>

jonnio avatar Dec 19 '19 19:12 jonnio

That wouldn’t be hard for me to take care of. And putting XSLT into the picture just for that seems to be a waste. Out of curiosity, is is specifically the Id attribute, but the other XML attributes are OK? Is it the name “Id” or just that the tags where it shows up need to not have any attributes?

Scott

On December 19, 2019 at 1:37:17 PM, Jon Osborn ([email protected]) wrote:

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.

<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>

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/BerryWorksSoftware/edireader/issues/16?email_source=notifications&email_token=ABQDKPEE4UWLFNPKB53WGULQZPEO3A5CNFSM4J5OHHMKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IBXVKSQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQDKPGURHKDP4L36Y6WSADQZPEO3ANCNFSM4J5OHHMA .

canabrook avatar Dec 19 '19 20:12 canabrook

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

jonnio avatar Jan 02 '20 16:01 jonnio