XSLT Atrtibute Value

P

parvus

Hi, I´m searching a solution for the following problem:
I´ve a generated XML Document like

<....>
<struct name="number" type="PartNumber">100</struct>
<struct name="identity" type="PartIdentity">1</struct>
<enum name="ex_identity" type="....."></enum>
<....>

Now i want to use a XSLT file to create a new structured XML file like

<....>
<number sort="struct" type="PartNumber">100</struct>
<identity sort="struct" type="PartIdentity">1</struct>
<ex_identity sort="enum" type="........

My problem ist, that i couldn´t read out the value of the attribute
"name" so i can´t
create a new element of it. Furthermore i need to create the other
attributes for the new element or maybe i can copy them easily(?). Does
anybody have any solution? PLZ help me im searching for a long time.

Big THX parvus
 
E

Edwin Kapauni

parvus wrote:
[...]
Now i want to use a XSLT file to create a new structured XML file like

<....>
<number sort="struct" type="PartNumber">100</struct>
<identity sort="struct" type="PartIdentity">1</struct>
<ex_identity sort="enum" type="........
[...]
Using enum is a good idea. But the above is not well formed XML.
Maybe you want something else?
 
P

parvus

Big THX for these very fast answers, but

<xsl:element name="{@name}"> ...

doesn´t work thats the problem. Furthermore with "{@name}" i don´t
get the value but the name of the attribute. I need the value. I
searched on www.w3.org but i didn´t find any solution.
 
S

Soren Kuula

Hi,
Hi, I´m searching a solution for the following problem:
I´ve a generated XML Document like

<....>
<struct name="number" type="PartNumber">100</struct>
<struct name="identity" type="PartIdentity">1</struct>
<enum name="ex_identity" type="....."></enum>
<....>

Now i want to use a XSLT file to create a new structured XML file like

<....>
<number sort="struct" type="PartNumber">100</struct>
<identity sort="struct" type="PartIdentity">1</struct>
<ex_identity sort="enum" type="........

My problem ist, that i couldn´t read out the value of the attribute
"name" so i can´t
create a new element of it.

Why couldn't you? Does <element name="{@name}"/> not work?

Furthermore i need to create the other
attributes for the new element or maybe i can copy them easily(?). Does
anybody have any solution? PLZ help me im searching for a long time.

<attribute name="sort"><value-of select="local-name()"/></attribute>

Soren
 
R

Richard Tobin

parvus said:
<xsl:element name="{@name}"> ...

doesn't work
Furthermore with "{@name}" i don´t
get the value but the name of the attribute. I need the value.

It gives you the value of the attribute. So there must be something
wrong with your version of it, or the stylesheet processor you're using.
You need to give us a complete stylesheet that shows the problem
if you want more help.

-- Richard
 
P

parvus

Ok THX Richard Tobin, now I think its really a problem of my stylesheet
processor. Which processor do you use? Im using this M$ IEXMLTLS.
 
S

Soren Kuula

parvus said:
Big THX for these very fast answers, but

<xsl:element name="{@name}"> ...

doesn´t work thats the problem. Furthermore with "{@name}" i don´t
get the value but the name of the attribute. I need the value. I
searched on www.w3.org but i didn´t find any solution.

Sure you did not write {name()} ??

Soren
 
P

parvus

So i post my XML and XSLT File maybe you´ll find the mistake:
XML:
-------

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="rdm.xslt"?>

<any>
<struct name="identity" type="IDM:RDM/Track:1.0">100</struct>
<struct name="strength" type="IDM:RDM/TrackStrength:1.0">200</struct>
<string name="test"></string>
</any>

XSLT:
--------

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="xml" indent="yes"/>

<xsl:template match="/">
<any>
<xsl:apply-templates/>
</any>
</xsl:template>

<xsl:template match="any/struct[1]">
<xsl:for-each select="@name">
<xsl:element name="{@name}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
</xsl:template>
.............

With this XSLT my Browser IE 6.0.2800.1106 replys:
"Um Knoten vom Typ 'ELEMENT' zu erstellen, muss ein gültiger Name
angegeben werden."

That means:
"When you want to create nodes type ELEMENT you should enter a valid
name"
 
P

parvus

Oh dear what a mistake :-(. BIG BIG BIG THX!!! It works. I think it was
a bad Newbie Mistake. Really THX!
 
S

Soren Kuula

parvus said:
So i post my XML and XSLT File maybe you´ll find the mistake:
XML:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="xml" indent="yes"/>

<xsl:template match="any/struct[1]">
<xsl:for-each select="@name">

Now you iterate over each name attribute of the first struct child of
any any element.... there's only one of those attributes of course
<xsl:element name="{@name}">

Now you try to take the value of the name attribute of the context node
.... which is the name attribute. In other words, you are selecting the
name atttribute of the name attribute ... there is none ;)
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
</xsl:template>

Instead try:
<xsl:template match="any/struct">
<xsl:element name="{@name}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>

OR

<xsl:template match="any/struct">
<xsl:for-each select="@name">
<xsl:element name="{.}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
</xsl:template>

(there's a difference). I think you want the first one (the second one
produces rather boring results, try it!! And using for-each over named
attributes is an unusual thing to do, since there is at most one anyway).


Soren
 
P

parvus

It works nice one. Another Question is how im able to make a break
after each Element?
Now my XSLT produce a file like:

"<?xml version="1.0" encoding="UTF-16"?><any><struct
type="IDL:RDM/Track:1.0"><id format="ulong">1</id><number
format="ulong">100</number></struct></any>"

Can i somehow control that my document becomes:

<?xml version="1.0" encoding="UTF-16"?>
<any>
<struct type="Part/Track">
<id format="ulong">1</id>
<number format="ulong">100</number>
</struct>
</any>

You know what i mean?! THX
 
P

parvus

It works without problems. But how can I copy the second attrivute?!
Its no problem NOW (THX to Soren!!!!) for me to create this:

<any>
<identity format="struct">100</identity>
<strenght format="struct">200</strength>
<test format="string"/>
</any>

I need to copy the original attribute (the second:
type="IDM:RDM/Track:1.0") so i want to become:

<any>
<identity format="struct" type="IDM:RDM/Track:1.0>100</identity>
<strenght format="struct"
type="IDM:RDM/TrackStrength:1.0">200</strength>
<test format="string"/>
</any>

plz help me :-/
When you want contact me @ ICQ UIN 67670783
 
P

parvus

It works without problems. But how can I copy the second attrivute?!
Its no problem NOW (THX to Soren!!!!) for me to create this:

<any>
<identity format="struct">100</identity>
<strenght format="struct">200</strength>
<test format="string"/>
</any>

I need to copy the original attribute (the second:
type="IDM:RDM/Track:1.0") so i want to become:

<any>
<identity format="struct" type="IDM:RDM/Track:1.0>100</identity>
<strenght format="struct"
type="IDM:RDM/TrackStrength:1.0">200</strength>
<test format="string"/>
</any>

plz help me :-/
When you want contact me @ ICQ UIN 67670783
 
M

Martin Honnen

parvus said:
"<?xml version="1.0" encoding="UTF-16"?><any><struct
type="IDL:RDM/Track:1.0"><id format="ulong">1</id><number
format="ulong">100</number></struct></any>"

Can i somehow control that my document becomes:

<?xml version="1.0" encoding="UTF-16"?>
<any>

Use
<xsl:eek:utput indent="yes" />
then in your stylesheet.
 
S

Soren Kuula

parvus said:
It works without problems. But how can I copy the second attrivute?!
Its no problem NOW (THX to Soren!!!!) for me to create this:
I need to copy the original attribute (the second:
type="IDM:RDM/Track:1.0") so i want to become:

<any>
<identity format="struct" type="IDM:RDM/Track:1.0>100</identity>
<strenght format="struct"
type="IDM:RDM/TrackStrength:1.0">200</strength>
<test format="string"/>
</any>

You have an

<element name=....></element>

instruction that generated the idendity, strength etc. elements.. right?

Try adding an attribute constructor:

<element name=....>
<attribute name="type"><value-of select="@type"/></attribute>
</element>

(this works if the context node is the element that HAS the type
attribute -- if it IS the type attribute, you have to .. we have talked
about that already... ;)

Soren
 
P

parvus

Hi Soren, sorry for annoying you but i cant realize my problem because
its to difficult for me :-( and i think its not an easy XML
transformation. You know what i want and i saw on your hp
http://dongfang.dk/ that you´re a xml / xslt pro ;-). So i´ll give
you an excerpt of my XML sourcefile, i need the same structure (!!!!)
after the transformation. I don´t know how i can realize it, its after
your help no problem for me to get the value of an attribute and im
able to create new elements with it, but i don´t know how to create
nodes and child elements etc. :-(! Here my sourcefile:

<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<struct type="Test:Test/Number:1.0">
<ulong name="id" type="Test:Test/NumberId:1.0">1</ulong>
<ulong name="number" type="Test:Test/NumberNumber:1.0">99</ulong>
<struct name="parvus" type="Test:Test/NumberParvus:1.0">
<enum name="value" type="Test:Test/NumberValue:1.0"
values="VALUE_UNKNOWN VALUE_KNOWN">VALUE_UNKNOWN</enum>
<string name="martin"
type="Test:Test/NumberMartin:1.0">unknown</string>
<string name="blacksheep"
type="Test:Test/NumberBlackSheep:1.0">peanut butter</string>
</struct>
<enum name="andi" type="Test:Test/NumberAndi:1.0"
values="ANDI_UNKNOWN ANDI_FRIEND ANDI_KNOWN">ANDI_UNKNOWN</enum>
<struct name="schalke" type="Test:Test/NumberSchalke:1.0">
<ulong name="minplace">0</ulong>
<ulong name="maxplace">10</ulong>
<string name="icke" type="Test:Test/NumberIcke:1.0">unknown</string>
<string name="bella"
type="Test:Test/NumberBella:1.0">unknown</string>
</struct>
</struct>
</document>

Can you pleeeeeeeeeeeeeeeaaaaaaaaaaaaaassssssssssse help me? I need the
same structure! It´s only the thing that the elements should not call
"struct, string ...." but they should call like the value of the "name"
attribute. Furthermore i add an attribute with the "datatype" like
datatype="string". Sadly i can´t realize it on my own :-( you´re my
last hope. You can contact me: parvus23 (at) web.de Thank you very much
indeed!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,851
Latest member
CliftonCor

Latest Threads

Top