users@jaxb.java.net

Re: Arbitrary name-value pairs

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

Oooh... yesss... that's the way to put arbitrary name-value pairs.

The XML using that complexType schema could have something like:

     <ConceptosExtraData>
         <Concepto>
             <data nam="codcli" val="value1"/>
             <data nam="extra2" val="value2"/>
             <data nam="extra3" val="value3"/>
         </Concepto>
         <Concepto>
             <data nam="codcli" val="valueA"/>
             <data nam="extra2" val="valueB"/>
             <data nam="extra3" val="valueC"/>
         </Concepto>
     </ConceptosExtraData>

Now I'm looking for a way to access each extraData.xml row of "Concepto"
from the corresponding row in the main xml, using xslt.

Maybe something like this:

-------------------------- BEGIN -----------------------
<xsl:for-each select="Conceptos/Concepto">

...

   <xsl:variable name="pos" select="position()"
   <td><xsl:value-of
select="document('extraData.xml')/ConceptosExtraData/Concepto[position()=$pos]/[@nam=codcli]/_at_val"/></td>

...

</xsl:for-each>

-------------------------- END -------------------------

I guess I don't know XPath enough, but I think it should be something
similar to that.

Am I right?

(I'm now with some other problem that doesn't let me test this now. I
will, as soon as I can)

Ely.


Wolfgang Laun escribió:
> A general way of storing name-value pairs in XML would be by by s.th. like:
>
> <xs:complexType name="NamValType">
> <xs:attribute name="nam" type="xs:string"/>
> <xs:attribute name="val" type="xs:string"/>
> </xs:complexType>
>
> or with a sequence of two elements. Association with a "detail" node could
> be
> done with an additional attribute.
>
> It's then very easy to locate the matching name-value pair. Creating
> elements
> from scratch is no problem in XSLT.
>
> -W
>
>
> On 25 May 2010 23:16, Ely Schoenfeld <ely.sun.1_at_mitalteli.com> wrote:
>
>> Hello all.
>>
>> First of all, I'm very new to XML, XSLT, JAXB and Java.
>> Please forgive me if i'm asking a dumb question.
>>
>> I would really appreciate any pointers to information you could give me. I
>> have been searching in google for days, but can't find anything useful.
>>
>> Sorry in advance for such a long message.
>>
>>
>> INTRODUCTION:
>>
>> I have an XSD file that I converted into classes using JAXB. The XML
>> generated files (invoices) are just fine in order to send information to the
>> other party.
>>
>> Now I need to print (in paper) the invoices. I thought I could use XSLT to
>> "transform" the xml, but I need to add some more information not included in
>> the xml file. That extra information isn't always the same, not even their
>> the attribute names.
>>
>>
>> PROBLEM:
>> So I thought I could create a second xml with "some" structure containing
>> that extra information that the XSLT script should be able to merge with the
>> original xml. (Maybe with the "document()" XSLT functin).
>>
>> When I need to get some data of the invoice header I've got no problem. I
>> always can do someting like:
>>
>> --- BEGIN ------------------------
>> <xsl:value-of
>> select="document('extra.xml')/ComprobanteExtraData/Receptor/_at_codcli"/>
>> --- END --------------------------
>>
>> The problem I'm facing now is that I haven't been able to get information
>> from the detail part of the invoice. The "detail" nodes from the original
>> xml that represent all the product details have no unique id, and the
>> extra.xml file doesn't either (but the extra.xml can be changed as I need).
>>
>>
>> WHAT I HAVE THOUGHT ABOUT IT:
>> I was thinking to add an id to the detail section of the extra.xml and add
>> somehow a counter to the for-each part of the XSLT.
>>
>> I got nowhere. It's kind of difficult to "create" an XML by hand. More if I
>> know I could use JAXB in some way.
>>
>> So I thought I should be able to generate an xml with basically the same
>> classes generated by the xsd, but to be able to add arbitrary name-value
>> pairs to those nodes instead of the ones generated from the original xsd.
>> That way I think I should be able to merge easily the main xml with the
>> extra.xml to transform it to a printable format (maybe html)
>>
>> I don't know how to do something like this... don't know how to add
>> arbitrary name-value pairs (or attributes) to classes. The only way I can
>> think of is a List that contains a LinkedList.... something like:
>>
>> --- BEGIN ------------------------
>> List<String> datos = new LinkedList<String>();
>> --- END --------------------------
>>
>> But I have no idea of how to transform it to XML or to maintain the
>> original XML structure easily. Or even if it's a good idea to do it this
>> way.
>>
>> If anybody has a tutorial, or has any pointers about how to solve this I
>> would really appreciate it.
>>
>> Thanks a lot.
>>
>> Ely
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>>
>>
>