Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Tricky XSLT question involving variables, serializing, processing instructions

From: Stryder <stryder100@-----.--->
To: NULL
Date: 4/2/2009 4:50:00 AM
I'm translating some complex DOM code (Perl) into XSLT and have run
into a problem I haven't been able to solve.  I'm working with Saxon 9
and Java 1.6.0_012.  Here's what's happening.

I've got this XML (really I've got thousands of levels in a document
but this'll suffice for this question)...

<?xml version="1.0" encoding="UTF8"?>
<toplevel>
    <level link-id="a6" level-type="INDEX2" level-nbr="4">
        <name>LIFO inventories</name>
        <applied-name>applied name</applied-name>
        <xref-list>. <i>See</i>
            <xref-index>
                <link-to link-
ref="txcnot_indx_top_2008q1_inventories">INVENTORIES</link-to>
                <link-to link-ref="dummy_linkref">DUMMY</link-to>
            </xref-index>
        </xref-list>
        <dont-touch-me>Please</dont-touch-me>
    </level>
</toplevel>

What I want to do is to make a deep copy of children of <level> up to
and not including <dont-touch-me> excluding <applied-name>, replace
<link-to link-ref=""> with <link-to-bwd link-to-frag="@link-ref"> ,
serialize it all and store it in a processing instruction.  I'm able
to grab the elements, serialize them with the Saxon serialize()
extension function and put them in a processing instruction, but I
haven't been able to replace the link-to elements.  Perhaps I'm going
about it all the wrong way.

Here's the XSLT I've got so far that serializes the desired elements
but doesn't translate the link-tos...

<?xml version="1.0" encoding="UTF8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0" xmlns:saxon="http://saxon.sf.net/" extension-element-
prefixes="saxon">
    <xsl:output indent="yes" encoding="UTF8"/>
    <xsl:output name="serializer" method="xml" indent="no" omit-xml-
declaration="yes"/>

    <xsl:template match="/">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="level">
        <xsl:variable name="make_me_a_pi">
            <xsl:copy-of select="node()[not(name() = 'applied-name')
and not(name() = 'dont-touch-me') and not(preceding-sibling::dont-
touch-me)]"/>
        </xsl:variable>
        <xsl:element name="level">
            <xsl:copy-of select="@*"/>
            <xsl:processing-instruction name="a_pi"><xsl:value-of
select="saxon:serialize($make_me_a_pi, 'serializer')"/></
xsl:processing-instruction>
        </xsl:element>
    </xsl:template>

    <xsl:template match="*">
        <xsl:apply-templates/>
    </xsl:template>
</xsl:stylesheet>

Any help would be greatly appreciated.

Thanks

Ralph



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent