users@jaxb.java.net

Re: Absolute XPath in a variable containing a set of nodes obtained with document() function

From: Ely Schoenfeld <ely.sun.1_at_mitalteli.com>
Date: Wed, 26 May 2010 15:14:48 -0500

I forgot to show how I'm "jumping" into the $main variable contents:

XSLT:
------------------------ BEGIN -------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
   <xsl:variable name="main" select="document(/files/file, /)"/>
   <xsl:variable name="extraData" select="document(/files/fileExtraData,
/)"/>

   <xsl:apply-templates select="$main" mode="process"/>
</xsl:template>

<xsl:template match="/" mode="process">
   0 [<xsl:value-of select="//_at_rfc"/>]<br></br>
   1 [<xsl:value-of select="/Comprobante/Receptor/_at_rfc"/>]<br></br>
...
</xsl:template>
------------------------ BEGIN -------------------------

Any pointers on how to print the Receptor's rfc attribute would be very
appreciated.

Thank you all in advance.

Ely.


Ely Schoenfeld escribió:
> Maybe this is not the right place to ask general XML-XSLT-XPATH questions.
>
> Any pointers to a better place would be appreciated.
>
> In the mean time:
>
> In may way to merging two xml files using XSLT, I decided to use one XML
> file containing the names of the files to be merged:
>
> ------------------------ BEGIN -------------------------
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <?xml-stylesheet type="text/xsl" href="catalog/xslt/facturaEnPapel.xslt"?>
> <files>
> <file>main.xml</file>
> <fileExtraData>extraData.xml</fileExtraData>
> </files>
> ------------------------ END ---------------------------
>
> And the "facturaEnPapel.xslt" is loading both files contents with:
>
> ------------------------ BEGIN -------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:variable name="main" select="document(/files/file, /)"/>
> <xsl:variable name="extraData"
> select="document(/files/fileExtraData, /)"/>
>
> ...
> ------------------------ END ---------------------------
>
>
> My problem is I can't seem to find how to get a particular node's value
> using an "absolute" XPath.
>
> For example... the "main" document contains:
>
> ------------------------ BEGIN -------------------------
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <Comprobante version="2.0" serie="ARH" folio="7909">
> <Emisor rfc="SDF531211GE2" nombre="NOMBRE1">
> ...
> </Emisor>
> <Receptor rfc="SEFT760217GA1" nombre="NOMBRE2">
> ...
> </Receptor>
> ...
> ------------------------ END ---------------------------
>
> Imagine I want to obtain the second rfc (the one in "Receptor").
> Here I show some tests, and their results:
>
> ------------------------ BEGIN -------------------------
> 0 [<xsl:value-of select="//_at_rfc"/>]<br></br>
> 1 [<xsl:value-of select="/Comprobante/Receptor/_at_rfc"/>]<br></br>
> 2 [<xsl:value-of select="Comprobante/Receptor/_at_rfc"/>]<br></br>
> 3 [<xsl:value-of select="//Comprobante/Receptor/_at_rfc"/>]<br></br>
> 4 [<xsl:value-of select="/Receptor/_at_rfc"/>]<br></br>
> 5 [<xsl:value-of select="Receptor/_at_rfc"/>]<br></br>
> 6 [<xsl:value-of select="//Receptor/_at_rfc"/>]<br></br>
>
> ........ results .........
>
> 0 [SDF531211GE2]
> 1 []
> 2 []
> 3 []
> 4 []
> 5 []
> 6 []
>
> ------------------------ END -------------------------
>
> So I tried to find what parents does the "rfc" containing node.
>
> I used the following XSLT code:
>
> ------------------------ BEGIN -------------------------
>
> ...
>
> ==[<br></br><xsl:apply-templates select="//_at_rfc"/>]==<br></br>
>
> ...
>
> <xsl:template match="@rfc">
> #[<xsl:call-template name="parents"/>]#<br></br>
> </xsl:template>
>
> ...
>
> <xsl:template name="parents">
> <xsl:for-each select="ancestor-or-self::*">
> <xsl:value-of select="concat(name(),'/')" />
> </xsl:for-each>
> <xsl:value-of select="." />
> </xsl:template>
> ------------------------ END ---------------------------
>
> And I got:
>
> ------------------------ BEGIN -------------------------
> ==[
> #[Comprobante/Emisor/SDF531211GE2]#
> #[Comprobante/Receptor/SEFT760217GA1]#
> ]==
> ------------------------ END ---------------------------
>
> So something like "/Comprobante/Receptor/_at_rfc" should work.
>
> Am I right?
>
> Any ideas about why it isn't working?
>
> I'm very very thankful for the pointers I always get from this mailing
> list.
>
> Ely.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net