S
Stryder
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">
<xslutput indent="yes" encoding="UTF8"/>
<xslutput 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="@*"/>
<xslrocessing-instruction name="a_pi"><xsl:value-of
select="saxon:serialize($make_me_a_pi, 'serializer')"/></
xslrocessing-instruction>
</xsl:element>
</xsl:template>
<xsl:template match="*">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
Any help would be greatly appreciated.
Thanks
Ralph
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">
<xslutput indent="yes" encoding="UTF8"/>
<xslutput 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="@*"/>
<xslrocessing-instruction name="a_pi"><xsl:value-of
select="saxon:serialize($make_me_a_pi, 'serializer')"/></
xslrocessing-instruction>
</xsl:element>
</xsl:template>
<xsl:template match="*">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
Any help would be greatly appreciated.
Thanks
Ralph