[XML4LIB] LC marcxml

Richard Rathmann Richard.Rathmann at noaa.gov
Thu Sep 19 13:40:23 EDT 2002


I didn't want to say anything in my initial response to Fernando, but I had an
idea for modifying the genvalidate.xsl file to be a little more helpful in
finding where errors occur and wanted to test it first.

I just changed the following:

    <xsl:template name="validateSubfields">
        <xsl:param name="sCodes"/>
        <xsl:for-each select="marc:subfield">
            <xsl:if test="not(contains($sCodes, @code))">
                <error type="InvalidSubfieldCode" tagID="{generate-id(.)}">
                    <code><xsl:value-of select="@code"/></code>
                    <value><xsl:value-of select="."/></value>
                </error>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>

to:

    <xsl:template name="validateSubfields">
        <xsl:param name="sCodes"/>
        <xsl:for-each select="marc:subfield">
            <xsl:if test="not(contains($sCodes, @code))">
                <error type="InvalidSubfieldCode" tagID="{generate-id(.)}">
                    <path>
                        <xsl:call-template name="getAbsXPath">
                            <xsl:with-param name="node" select="." />
                        </xsl:call-template>
                    </path>
                    <code><xsl:value-of select="@code"/></code>
                    <value><xsl:value-of select="."/></value>
                </error>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>

and added the following as a child of <xsl:stylesheet> (I put it after the
<xsl:output> at the top):

    <xsl:template name="getAbsXPath">
        <xsl:param name="node" />
        <xsl:if test="$node">
            <xsl:variable name="parent" select="$node/parent::*" />
            <xsl:call-template name="getAbsXPath">
                <xsl:with-param name="node" select="$parent" />
            </xsl:call-template>
            <xsl:text>/</xsl:text>
            <xsl:value-of select="name($node)" />
            <xsl:text>[</xsl:text>
            <xsl:value-of select="count($node/preceding-sibling::*[name() =
name($node)]) + 1" />
            <xsl:text>]</xsl:text>
        </xsl:if>
    </xsl:template>

and the new <path> child showed the absolute XPath to the offending <subfield>
in the example MARC-XML file.

I didn't try it, but you should be able to similarly add the five lines I added
in the "validateSubfields" template to all the templates that output <error>
elements and get similar results for them as well.

Richard


--
===========================
Richard E. Rathmann
TPMC Web Designer/Programmer
NOAA Coastal Services Center
2234 S Hobson Avenue
Charleston, SC  29405-2413
(843) 740-1314 (phone)
(843) 740-1315 (fax)
Richard.Rathmann at noaa.gov




More information about the xml4lib mailing list