Need help with XML structure change
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 1
- Joined: Sat Aug 13, 2005 10:18 am
- Location: South Bend, IN
- Contact:
Need help with XML structure change
Hi,
I am a self-confessed XML newbie, and I suspect my question is probably very simple, but I don't even know what to search for, as I don't know the right terms and such. So I'm hoping someone here can help me.
I recently downloaded oXygen and am trying to figure out how to perform a specific function with it. What I need to do is quite simple. This is the current structure of my XML document:
I need to make it so that the "thread ID" number appears on EVERY comment, not just at the beginning of each comment thread. So for example, it could look like this:
Or something along those lines. Bottom line, I just need to find an automated way of sticking that thread id number inside the "comment" attribute. If someone can show me the basics, I can probably figure out the specifics... I just need a starting point.
In case you're wondering, this conversion is necessary because I am exporting to a MySQL database and I need the ID number in every comment in order to sychronise with the existing entries in the database.
Any help would be much appreciated! Thanks!
--Brendan Loy
I am a self-confessed XML newbie, and I suspect my question is probably very simple, but I don't even know what to search for, as I don't know the right terms and such. So I'm hoping someone here can help me.
I recently downloaded oXygen and am trying to figure out how to perform a specific function with it. What I need to do is quite simple. This is the current structure of my XML document:
Code: Select all
<thread id="90815878">
<comment>
<datetime>2003-03-17T01:48:14-05:00</datetime>
<name>Andrew</name>
<email>uscrepublican@hotmail.com</email>
<uri></uri>
<ip>24.24.241.28</ip>
<text><![CDATA[Man, the West is tough. What were they thinking?!? Arizona, Kansas, Duke, and Illinois--any other year and that could be your Final Four. Illinois and Duke both won their conference tourneys, and Arizona is ranked #1. Duke is always tough. Sheesh.]]></text>
</comment>
<comment>
<datetime>2003-03-17T01:54:36-05:00</datetime>
<name>Andrew</name>
<email>uscrepublican@hotmail.com</email>
<uri></uri>
<ip>24.24.241.28</ip>
<text><![CDATA[Wow, picking the semifinal matchups in the East is turning out to be quite difficult. Each matchup I show could go either way.]]></text>
</comment>
</thread>
Code: Select all
<thread id="90815878">
<comment>
<threadid>90815878</threadid>
<datetime>2003-03-17T01:48:14-05:00</datetime>
<name>Andrew</name>
<email>uscrepublican@hotmail.com</email>
<uri></uri>
<ip>24.24.241.28</ip>
<text><![CDATA[Man, the West is tough. What were they thinking?!? Arizona, Kansas, Duke, and Illinois--any other year and that could be your Final Four. Illinois and Duke both won their conference tourneys, and Arizona is ranked #1. Duke is always tough. Sheesh.]]></text>
</comment>
<comment>
<threadid>90815878</threadid>
<datetime>2003-03-17T01:54:36-05:00</datetime>
<name>Andrew</name>
<email>uscrepublican@hotmail.com</email>
<uri></uri>
<ip>24.24.241.28</ip>
<text><![CDATA[Wow, picking the semifinal matchups in the East is turning out to be quite difficult. Each matchup I show could go either way.]]></text>
</comment>
</thread>
In case you're wondering, this conversion is necessary because I am exporting to a MySQL database and I need the ID number in every comment in order to sychronise with the existing entries in the database.
Any help would be much appreciated! Thanks!
--Brendan Loy
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Brendan,
For this kind of problems the general solution is to start with a copy template and then add specific matches on the nodes that you want to change. A possible stylesheet that does the change you requested is below:
Best Regards,
George
For this kind of problems the general solution is to start with a copy template and then add specific matches on the nodes that you want to change. A possible stylesheet that does the change you requested is below:
Code: Select all
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="comment">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<threadid><xsl:value-of select="../@id"/></threadid>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
George
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service