xsl-list
[Top] [All Lists]

UPDATE: [xsl] Building XML from XPATHS in XSLT 2.0

2004-04-26 16:58:11
Hi guys,

/ 'Michael Kay' says:
You presumably mean "build an XML document for which none
of these XPath expressions returns an empty sequence."

Yes, this is exactly what I mean!!

/ 'Michael Kay' says:
You say "any valid XPath". Are you restricting this to path expressions?
Absolute path expressions? Are they always evaluated with the root as the
context node?

I suppose I will have to use Absolute path and start with simple XPATH then
try to deal with more complex examples later... I do not envisage the XPATHS
will ever create invalid XML like in the /a /b example so it isn't important
(just it might be nice to also add some error checking later if I get time!)

I am still wondering whether full XPATH tokenisation will be possible in
XSLT 2.0? And, also how I merge multiple xml fragents as I create single XML
fragments from each path. I have roughly outlined a start of some code
(probably pretty erroneus and missing a lot of detail at this point!!)

XPATH.xml

<?xml version="1.0" encoding="UTF-8"?>
<frame>
 <block
XPATH="/ClinicalDocument/recordTarget/patientRole/patientPatient/name/family
"/>
 <block
XPATH="/ClinicalDocument/recordTarget/patientRole/patientPatient/name/given"
/>
 <block
XPATH="/ClinicalDocument/component/bodyChoice/StructuredBody/component/bodyC
hoice/StructuredBody/component/section/component/section/entry/entryChoice/O
bservation/value"/>
 <block
XPATH="/ClinicalDocument/component/bodyChoice/StructuredBody/component/bodyC
hoice/StructuredBody/component/section[(_at_)title=$section-name]/component/secti
on[(_at_)title=$subsection-name]/entry/entryChoice/Observation/participant/partic
ipatingEntity/associatedPerson/name"/>
 <block
XPATH="/ClinicalDocument/component/bodyChoice/StructuredBody/component/bodyC
hoice/StructuredBody/component/section/component/section/entry/entryChoice/O
bservation/value"/>
</frame>


XPATH.xsl

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
    <xsl:output method="xml" encoding="ISO-8859-1" indent="yes"/>
    <!--+
        |     INITIAL INVOCATION
        +-->
    <xsl:template match="/">
        <xsl:apply-templates/>
    </xsl:template>
    <!--+
        |     TEMPLATE TO STEP THROUGH EACH XPATH AND MAKE NEW ADDITIONS
        +-->
    <xsl:template match="block">
        <xsl:param name="xml-fragment"/>
        <xsl:variable name="current-xml-build">
            <xsl:call-template name="merge-xml-structures">
                <xsl:with-param name="xml-fragment" select="$xml-fragment"/>
                <xsl:with-param name="xml-fragment-2">
                    <xsl:call-template name="build-xml-from-path"/>
                </xsl:with-param>
            </xsl:call-template>
        </xsl:variable>
        <xsl:apply-templates select="following-sibling::block[1]">
            <xsl:with-param name="xml-fragment"
select="$current-xml-build"/>
        </xsl:apply-templates>
        <xsl:if test="last()">
            <xsl:copy-of select="$current-xml-build"/>
        </xsl:if>
    </xsl:template>
    <!--+
        |     TEMPLATE TO BUILD SOME XML FROM A SINGLE XPATH
        +-->
    <xsl:template name="build-xml-from-path">
        <xsl:variable name="tokenizedXPATH" select="tokenize(@XPATH,'/')"/>
        <xsl:for-each select="$tokenizedXPATH">
            <!-- in progress -->
        </xsl:for-each>
    </xsl:template>
    <!--+
        |     TEMPLATE TO BUILD SOME XML FROM A SINGLE XPATH
        +-->
    <xsl:template name="merge-xml-structures">
        <xsl:param name="xml-fragment"/>
            <!-- in progress -->
    </xsl:template>
</xsl:stylesheet>


Many Thanks in Advance for any suggestions,

Gary




-----Original Message-----
From: Michael Kay [mailto:mhk(_at_)mhk(_dot_)me(_dot_)uk]
Sent: 26 April 2004 22:36
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Building XML from XPATHS in XSLT 2.0


Some thoughts to help you specify the problem more precisely:

You presumably mean "build an XML document for which none of these XPath
expressions returns an empty sequence."

You say "any valid XPath". Are you restricting this to path expressions?
Absolute path expressions? Are they always evaluated with the root as the
context node?

In general of course there may be no solution. For example if you have two
paths /a and /b there is no document that gives a non-empty answer for both.

Michael Kay

-----Original Message-----
From: gary(_at_)rapport(_dot_)net [mailto:gary(_at_)rapport(_dot_)net]
Sent: 26 April 2004 20:51
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Building XML from XPATHS in XSLT 2.0

Hi Guys,

I have just started working on a problem which is quite
interesting. I have
some xml that can contain any valid XPATH as an attribute
string and I would
like to go through all the XPATHS listed and build some XML
based on them.
i.e.

<frame>
 <block
XPATH="/ClinicalDocument/recordTarget/patientRole/patientPatie
nt/name/family
"/>
 <block
XPATH="/ClinicalDocument/recordTarget/patientRole/patientPatie
nt/name/given"
/>
 <block
XPATH="/ClinicalDocument/component/bodyChoice/StructuredBody/c
omponent/bodyC
hoice/StructuredBody/component/section/component/section/entry
/entryChoice/O
bservation/value"/>
 <block
XPATH="/ClinicalDocument/component/bodyChoice/StructuredBody/c
omponent/bodyC
hoice/StructuredBody/component/section[(_at_)title=$section-name]/c
omponent/secti
on[(_at_)title=$subsection-name]/entry/entryChoice/Observation/part
icipant/partic
ipatingEntity/associatedPerson/name"/>
 <block
XPATH="/ClinicalDocument/component/bodyChoice/StructuredBody/c
omponent/bodyC
hoice/StructuredBody/component/section/component/section/entry
/entryChoice/O
bservation/value"/>
</frame>

If anyone has already done something similar to this and
wants to share some
code it would be appreciated or if anyone is interstested in
the solution
let me know and I will post the group back when I have found
a solution to
the problem!

Many Thanks

Gary Cornelius



--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--




--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--





<Prev in Thread] Current Thread [Next in Thread>