How to deal with unknown element? Help!!!!

3 views
Skip to first unread message

John Zhang

unread,
Jun 24, 2011, 11:11:18 AM6/24/11
to Dexter-XSL
Xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
-<rootElement>
-<elementOne>
-<A>A1</A>
-<B>B1</B>
-<C>C1</C>
-<D>D1</D>
-<E>E1</E>
</elementOne>
</rootElement>

Now, it will contain A element, so I use “If” statement to test
whether there is A element and get the value as attribute for the new
xml. The rest parts, like B, C, D, E, it may contain all of them, or
part of them, or more than these(it may have F, G, H and so on). So
they are unknown elements, what I want to do is to get all the tag
name and the value pairs, so the new xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
-<newRootElement>
-<newElementOne>
-<Detail tag=”A” value=”A1” /Detail>
-<Detail tag=”B” value=”B1” /Detail>
-<Detail tag=”C” value=”C1” /Detail>
-<Detail tag=”D” value=”D1” /Detail>
-<Detail tag=”E” value=”E1” /Detail>

How can I achieve that?

Michael Dykman

unread,
Jun 24, 2011, 12:14:32 PM6/24/11
to dexte...@googlegroups.com
correction: (I really should proof read more before pressing send)

<newRootElement>
<newElementOne>
 <Detail  dx:each="rootElement/elementOne/*"
dx:attrs="|tag:name()|value:." tag=”A” value=”A1” /Detail>
 <Detail  dx:ignore=""  tag=”B” value=”B1” /Detail>
</newElementOne>
<newRootElement>

On Fri, Jun 24, 2011 at 12:10 PM, Michael Dykman <mdy...@gmail.com> wrote:
> John,
>
> to approach this in dexter would be pretty simple:
>
> <newRootElement>
> <newElementOne>
>  <Detail  dx:each="rootElement/elementOne/*" tag=”A” value=”A1” /Detail>
>  <Detail  dx:ignore=""  tag=”B” value=”B1” /Detail>
>  </newElementOne>
> <newRootElement>
>
>
> compiled through dexter will yield a stylesheet to effect your changes.
>
>  - michael dykman

>> --
>> You received this message because you are subscribed to the Google Groups "Dexter-XSL" group.
>> To post to this group, send email to dexte...@googlegroups.com.
>> To unsubscribe from this group, send email to dexter-xsl+...@googlegroups.com.
>> For more options, visit this group at http://groups.google.com/group/dexter-xsl?hl=en.
>>
>>
>
>
>
> --
>  - michael dykman
>  - mdy...@gmail.com
>
>  May the Source be with you.
>

--
 - michael dykman
 - mdy...@gmail.com

 May the Source be with you.

Michael Dykman

unread,
Jun 24, 2011, 12:10:59 PM6/24/11
to dexte...@googlegroups.com
John,

to approach this in dexter would be pretty simple:

<newRootElement>
<newElementOne>
<Detail  dx:each="rootElement/elementOne/*" tag=”A” value=”A1” /Detail>
<Detail  dx:ignore="" dx:attrs="|tag:name()|value:." /Detail>
</newElementOne>
<newRootElement>


compiled through dexter will yield a stylesheet to effect your changes.

- michael dykman

On Fri, Jun 24, 2011 at 11:11 AM, John Zhang <johngua...@gmail.com> wrote:

Guangyun Zhang

unread,
Jun 24, 2011, 4:14:41 PM6/24/11
to dexte...@googlegroups.com
Michael,

Thank you for your reply. I never used dexter before, does it have requirements to use dexter? Currently I am using xsl to do the translation. I mean can I use dexter in xsl? 

Thank you again, Michael.

John

On Fri, Jun 24, 2011 at 12:10 PM, Michael Dykman <mdy...@gmail.com> wrote:

Tracy Lauren

unread,
Jun 24, 2011, 2:09:18 PM6/24/11
to dexte...@googlegroups.com
Great example Michael.

the <detail dx:ignore="" /> tag is unnecessary since the compiler will
drop that node anyways.

I personally tend to delete those nodes form the code base to avoid
confusion, but it may be useful
for looking at the original source.

Tracy

Michael Dykman

unread,
Jun 26, 2011, 6:10:26 PM6/26/11
to dexte...@googlegroups.com
Dexter is a tool for generating XSL. It is designed to address the
problem of creating XSL files to turn XML data into HTML result pages.
The patterns that are used in XSL for such tasks are well known but
the XSL language itself is heavy requiring a lot of markup to
implement those simple things. Dexter automates the generation of XSL
from example output documents (ie HTML) which have additional
attributes added to describe the relationship of the html out to the
expect xml data.

- michael dykman

Guangyun Zhang

unread,
Jun 27, 2011, 12:13:07 PM6/27/11
to dexte...@googlegroups.com
Hi, Michael,

Thank you so much. Can Dexter use for the XML into XML(different format)? I do not think it can. If so, is there any alternative method to do XML into XML with unknown elements?

Thank you again, Michael.

--Warm Regards,
John

Michael Dykman

unread,
Jun 28, 2011, 11:48:41 AM6/28/11
to dexte...@googlegroups.com
Given the example below, put it in a file 'foo.xml'

>> >> <newRootElement>
>> >> <newElementOne>
>> >>  <Detail  dx:each="rootElement/elementOne/*" tag=”A” value=”A1”
>> >> /Detail>
>> >>  <Detail  dx:ignore="" dx:attrs="|tag:name()|value:." /Detail>
>> >>  </newElementOne>
>> >> <newRootElement>

#dexter.bat in windows

running $ dexter.sh foo.xml
produces "foo.xml.xsl"

running your XML data through that XSLT-1.0 stylesheet with any
avilable XSLT v1 processor will give you the output you are looking
for. The xpath function "name()" gives the name of the current
element so it needs not be known.

$ xsltproc foo.xml.xsl mydata.xml

I recommend building dexter it although I would be pleased to provide
you with a binary of the latest version.


On Mon, Jun 27, 2011 at 12:13 PM, Guangyun Zhang

Reply all
Reply to author
Forward
0 new messages