XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 24th, 2011, 02:07 PM
dba_frog's Avatar
dba_frog dba_frog is offline
cave painting, the 1st Opn Src
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2003
Posts: 532 dba_frog Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 16 h 3 m 34 sec
Reputation Power: 0
[[ split from http://forums.devshed.com/xml-progr...ion-808394.html --requinix ]]
Quote:
Originally Posted by requinix
You can't really do JOINs, but you can search for nodes that match a condition.


I'm trying to do a fair amount of data manipulation with xml files, if you can't 'join', how much transformation\query can you do?

I don't want to suck the xml into mysql, but it almost seems worth it to get the data results I'm looking for.

Is there a compelling reason not to manipulate the xml in a db and spit back the results?
__________________
Curious by Nature,
Linux by Choice
Lawson ERP reference tools: Lawsuss.com

Last edited by requinix : May 24th, 2011 at 03:55 PM.

Reply With Quote
  #2  
Old May 24th, 2011, 03:56 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,682 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 2 h 24 m 24 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
It depends. What does your XML look like and what are you trying to get from it?

Reply With Quote
  #3  
Old May 25th, 2011, 08:43 AM
dba_frog's Avatar
dba_frog dba_frog is offline
cave painting, the 1st Opn Src
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2003
Posts: 532 dba_frog Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 16 h 3 m 34 sec
Reputation Power: 0
It is fairly complex from the system and I want to do some level of display and modification.
I'll keep plugging away at it.

Reply With Quote
  #4  
Old May 25th, 2011, 10:25 AM
dba_frog's Avatar
dba_frog dba_frog is offline
cave painting, the 1st Opn Src
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2003
Posts: 532 dba_frog Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 16 h 3 m 34 sec
Reputation Power: 0
Multi template with 'join'

[[ thread merged... --requinix ]]

I have a file with printers and rules in it. I need to output the printer that matches it's rules.

xml
Code:
<SEC>
  <SECCLASS >
   <AttrType>ENV</AttrType>
   <AttrName>PROD</AttrName>
   <Attrref></Attrref>
  </SECCLASS>
  <SECCLASS>
    <AttrType>PRT</AttrType>
    <AttrName>tr_001</AttrName>
   <Attrref>g_01</Attrref>
  </SECCLASS>
  <SECCLASS>
    <AttrType>PRT</AttrType>
    <AttrName>tr_002</AttrName>
   <Attrref>g_02</Attrref>
  </SECCLASS>
  <SECCLASS>
    <AttrType>ITEM</AttrType>
    <AttrName>class</AttrName>
   <Attrref></Attrref>
  </SECCLASS>
<SEC>
<RULE>
   <Attrrule>Portrait</Attrrule>
   <Attrref>g_01</Attrref>
</RULE>
<RULE>
   <Attrrule>Landscape</Attrrule>
   <Attrref>g_02</Attrref>
</RULE>
<RULE>
   <Attrrule>A17</Attrrule>
   <Attrref>g_03</Attrref>
</RULE>
<RULE>
   <Attrrule>Color</Attrrule>
   <Attrref>g_04</Attrref>
</RULE>


xsl
Code:
<xsl:template match="SEC">
  <xsl:apply-templates select="SECCLASS/ATTR[AttrType ='PRT']"/>
  <xsl:apply-templates select="SECCLASS/ATTR[Attrref = RULE/Attrref]"/>
</xsl:template>
  <xsl:template match="SECCLASS/ATTR">
   <tr>
    <td>
     <xsl:value-of select="SEC/SECCLASS/AttrName"/>
   </td>
    <td>
     <xsl:value-of select="RULE/Attrrule"/>
   </td>
  </tr>
</xsl:template>


So IF it is a Printer, then I want the Printer Name and the corresponding Printer Rule. I just don't know if I can have multiple selects in a template, and can I mix the nodes?

Last edited by requinix : May 25th, 2011 at 01:32 PM.

Reply With Quote
  #5  
Old May 25th, 2011, 12:51 PM
xml-profi xml-profi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 190 xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 7 h 8 m 25 sec
Reputation Power: 48
Send a message via ICQ to xml-profi
your xml file ist not valid
think like xsl in xml so it will going on

every xml file must have a root element

so you have xml like this
Code:
<?xml version="1.0"?>
<root>
	<SEC>
		<SECCLASS>
			<AttrType>ENV</AttrType>
			<AttrName>PROD</AttrName>
			<Attrref></Attrref>
		</SECCLASS>
		<SECCLASS>
			<AttrType>PRT</AttrType>
			<AttrName>tr_001</AttrName>
			<Attrref>g_01</Attrref>
		</SECCLASS>
		<SECCLASS>
			<AttrType>PRT</AttrType>
			<AttrName>tr_002</AttrName>
			<Attrref>g_02</Attrref>
		</SECCLASS>
		<SECCLASS>
			<AttrType>ITEM</AttrType>
			<AttrName>class</AttrName>
			<Attrref></Attrref>
		</SECCLASS>
	</SEC>
	<RULE>
		<Attrrule>Portrait</Attrrule>
		<Attrref>g_01</Attrref>
	</RULE>
	<RULE>
		<Attrrule>Landscape</Attrrule>
		<Attrref>g_02</Attrref>
	</RULE>
	<RULE>
		<Attrrule>A17</Attrrule>
		<Attrref>g_03</Attrref>
	</RULE>
	<RULE>
		<Attrrule>Color</Attrrule>
		<Attrref>g_04</Attrref>
	</RULE>
</root>

xsl to testing
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" method="html"/>
	<xsl:template match="/">
		<html>
			<style type="text/css">table
		{
		border:solid 1px black;
		}
		th,td
		{
		border:solid 1px black;
		}
		.head
		{
		background-color:#9acd32;
		}</style>
			<body>
				<h2>Printers</h2>
				<table>
					<tr class="head">
						<th>Printers</th>
						<th>Info</th>
						<th>Rule</th>
					</tr>
					<xsl:apply-templates select="root"/>
				</table>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="root">
		<xsl:apply-templates select="SEC"/>
	</xsl:template>
	<xsl:template match="SEC">
		<xsl:apply-templates select="SECCLASS[AttrType = 'PRT']"/>
	</xsl:template>
	<xsl:template match="SECCLASS">
		<tr>
			<td>
				<xsl:value-of select="AttrType"/>
			</td>
			<td>
				<xsl:value-of select="AttrName"/>
			</td>
			<!--
			<td>
				<xsl:value-of select="Attrref"/>
			</td>
			-->
			<xsl:variable name="attrref" select="Attrref"/>
			<xsl:apply-templates select="../../RULE[Attrref=$attrref]"/>
		</tr>
	</xsl:template>
	<xsl:template match="RULE">
		<td>
			<xsl:value-of select="Attrrule"/>
		</td>
	</xsl:template>
</xsl:stylesheet>

result

Code:
<html>
  <style type="text/css">table
		{
		border:solid 1px black;
		}
		th,td
		{
		border:solid 1px black;
		}
		.head
		{
		background-color:#9acd32;
		}
  </style>
  <body>
    <h2>Printers</h2>
    <table>
      <tr class="head">
        <th>Printers</th>
        <th>Info</th>
        <th>Rule</th>
      </tr>
      <tr>
        <td>PRT</td>
        <td>tr_001</td>
        <td>Portrait</td>
      </tr>
      <tr>
        <td>PRT</td>
        <td>tr_002</td>
        <td>Landscape</td>
      </tr>
    </table>
  </body>
</html>
__________________
Helmut Hagemann Germany

fallen to the bottom of the facts?
I reach my hand and we go together


wer lesen und google kann ist klar im Vorteil
who read and google is able is clear in the advantage

Reply With Quote
  #6  
Old May 25th, 2011, 02:44 PM
dba_frog's Avatar
dba_frog dba_frog is offline
cave painting, the 1st Opn Src
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2003
Posts: 532 dba_frog Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 16 h 3 m 34 sec
Reputation Power: 0
I'm sorry, yes there was a root to the xml. I cut the portion out that I was testing. Thanks for being able to fix that and answer my question.

Reply With Quote
  #7  
Old May 26th, 2011, 10:14 AM
dba_frog's Avatar
dba_frog dba_frog is offline
cave painting, the 1st Opn Src
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2003
Posts: 532 dba_frog Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 16 h 3 m 34 sec
Reputation Power: 0
Code:
	<xsl:template match="SECCLASS">
                 <xsl:for-each value="AttrName">
                  <xsl:sort value="AttrName">
		<tr>
			<td>
				<xsl:value-of select="AttrType"/>
			</td>
			<td>
				<xsl:value-of select="AttrName"/>
			</td>
			<!--
			<td>
				<xsl:value-of select="Attrref"/>
			</td>
			-->
			<xsl:variable name="attrref" select="Attrref"/>
			<xsl:apply-templates select="../../RULE[Attrref=$attrref]"/>
		</tr>
         </xsl:for-each>
	</xsl:template>

So I added a SORT to the template and it blew up. Where to I put a sort on the AttrName to get an ordered list back?

Reply With Quote
  #8  
Old June 1st, 2011, 10:50 AM
xml-profi xml-profi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 190 xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 7 h 8 m 25 sec
Reputation Power: 48
Send a message via ICQ to xml-profi
you have to make yourself what
and not always ask

and please work with template thoughtless
and not as a programmer

not use the for-each is drawn off as a programmer


Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" method="html"/>
	<xsl:template match="/">
		<html>
			<style type="text/css">table
		{
		border:solid 1px black;
		}
		th,td
		{
		border:solid 1px black;
		}
		.head
		{
		background-color:#9acd32;
		}</style>
			<body>
				<h2>Printers</h2>
				<table>
					<tr class="head">
						<th>Printers</th>
						<th>Info</th>
						<th>Rule</th>
					</tr>
					<xsl:apply-templates select="root"/>
				</table>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="root">
		<xsl:apply-templates select="SEC"/>
	</xsl:template>
	<xsl:template match="SEC">
		<xsl:apply-templates select="SECCLASS[AttrType = 'PRT']">
		<xsl:sort select="AttrName" order="ascending"/>
		</xsl:apply-templates>
	</xsl:template>
	<xsl:template match="SECCLASS">
		<tr>
			<td>
				<xsl:value-of select="AttrType"/>
			</td>
			<td>
				<xsl:value-of select="AttrName"/>
			</td>
			<!--
			<td>
				<xsl:value-of select="Attrref"/>
			</td>
			-->
			<xsl:variable name="attrref" select="Attrref"/>
			<xsl:apply-templates select="../../RULE[Attrref=$attrref]"/>
		</tr>
	</xsl:template>
	<xsl:template match="RULE">
		<td>
			<xsl:value-of select="Attrrule"/>
		</td>
	</xsl:template>
</xsl:stylesheet>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Worth loading XML into a database to search? + Multi template with 'join'

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap