RPGDXThe center of Indie-RPG gaming
Not logged in. [log in] [register]
 
 
Post new topic Reply to topic  
View previous topic - View next topic  
Author Message
XMark
Guitar playin' black mage


Joined: 30 May 2002
Posts: 870
Location: New Westminster, BC, Canada

PostPosted: Tue May 24, 2005 12:32 am    Post subject: XSLT question [quote]

Okay, let's say that I have an XML data structure something like this:
Code:

<weapons>
  <weapon id = "is">
    <name>iron sword</name>
    <str>23</str>
  </weapon>
  <weapon id = "ba">
    <name>battle axe</name>
    <str>34</str>
  </weapon>
</weapons>

<enemies>
  <enemy id = "eg">
    <name>Evil Guard</name>
    <weapon>is</weapon>
  </enemy>
</enemies>


Now, if I make an XSLT file, and I'm looping through the enemies with an <xsl:for-each> loop, how do I get it to show the name of the weapon rather than the id?

note: this is just a quick-and-dirty example file, I'm aware that the id naming scheme isn't very practical.
_________________
Mark Hall
Abstract Productions
I PLAYS THE MUSIC THAT MAKES THE PEOPLES FALL DOWN!
Back to top  
XMark
Guitar playin' black mage


Joined: 30 May 2002
Posts: 870
Location: New Westminster, BC, Canada

PostPosted: Tue May 24, 2005 3:23 am    Post subject: [quote]

Figured it out. It's all about the <xsl:key> command.

Geez, all this studying I'm doing for my XML exam day after tomorrow is enough to make me hate the letter X...
_________________
Mark Hall
Abstract Productions
I PLAYS THE MUSIC THAT MAKES THE PEOPLES FALL DOWN!
Back to top  
Nephilim
Mage


Joined: 20 Jun 2002
Posts: 414

PostPosted: Tue May 24, 2005 5:25 am    Post subject: [quote]

I think what you want to do is use xsl:value-of to select out of the weapons table using XPath notation. I haven't done this before, so I could be totally wrong on this, but I suspect it would look something like this:
Code:

  <xsl:value-of select="/weapons/weapon[@id=current()/weapon]">

Highly, highly, highly untested code. What I think this might say is this: select the root-level 'weapons' node, then the 'weapon' children of that node whose 'id' attribute is the same as the current enemy node's weapon value.
_________________
Visit the Sacraments web site to play the game and read articles about its development.
Back to top  
XMark
Guitar playin' black mage


Joined: 30 May 2002
Posts: 870
Location: New Westminster, BC, Canada

PostPosted: Fri Jun 03, 2005 8:46 pm    Post subject: [quote]

I got another question...

How would I make a php file that simply grabs an XML file and an XSL file and outputs what would be generated from them?

I've been looking through php.net's documentation but they seem to just go into long-winded explanations on every detail of the parser commands without providing any simple examples of their use.
_________________
Mark Hall
Abstract Productions
I PLAYS THE MUSIC THAT MAKES THE PEOPLES FALL DOWN!
Back to top  
LeoDraco
Demon Hunter


Joined: 24 Jun 2003
Posts: 584
Location: Riverside, South Cali

PostPosted: Sat Jun 04, 2005 12:22 am    Post subject: [quote]

I've not messed around with any of this, so this might not be what you are looking for. However...

After looking through the manual, this looks more or less like what you are after. Specifically, example 2.
_________________
"...LeoDraco is a pompus git..." -- Mandrake
Back to top  
XMark
Guitar playin' black mage


Joined: 30 May 2002
Posts: 870
Location: New Westminster, BC, Canada

PostPosted: Sat Jun 04, 2005 12:23 am    Post subject: [quote]

Yeah, I tried that, but it appears that my web host's version of PHP doesn't have that particular library.
_________________
Mark Hall
Abstract Productions
I PLAYS THE MUSIC THAT MAKES THE PEOPLES FALL DOWN!
Back to top  
LeoDraco
Demon Hunter


Joined: 24 Jun 2003
Posts: 584
Location: Riverside, South Cali

PostPosted: Sat Jun 04, 2005 12:27 am    Post subject: [quote]

Have you tried the XSL library? There's a rather crude example under its constructor documentation.

Edit: Also, if you knew that your web server had an xslt processor installed, you could always try execing it, but that might be dangerous, if you are not careful...
_________________
"...LeoDraco is a pompus git..." -- Mandrake
Back to top  
Post new topic Reply to topic Page 1 of 1 All times are GMT
 



Display posts from previous:   
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum