The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> XML Programming
|
Worth loading XML into a database to search? + Multi template with 'join'
Discuss Worth loading XML into a database to search? + Multi template with 'join' in the XML Programming forum on Dev Shed. Worth loading XML into a database to search? + Multi template with 'join' XML Programming forum discussing XML and related technologies, including XUL and XSL. XML is a self-describing file format, designed for maximum compatibility between applications.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 24th, 2011, 02:07 PM
|
 |
cave painting, the 1st Opn Src
|
|
Join Date: Jun 2003
Posts: 532
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.
|

May 24th, 2011, 03:56 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
It depends. What does your XML look like and what are you trying to get from it?
|

May 25th, 2011, 08:43 AM
|
 |
cave painting, the 1st Opn Src
|
|
Join Date: Jun 2003
Posts: 532
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.
|

May 25th, 2011, 10:25 AM
|
 |
cave painting, the 1st Opn Src
|
|
Join Date: Jun 2003
Posts: 532
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.
|

May 25th, 2011, 12:51 PM
|
|
|
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
|

May 25th, 2011, 02:44 PM
|
 |
cave painting, the 1st Opn Src
|
|
Join Date: Jun 2003
Posts: 532
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.
|

May 26th, 2011, 10:14 AM
|
 |
cave painting, the 1st Opn Src
|
|
Join Date: Jun 2003
Posts: 532
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?
|

June 1st, 2011, 10:50 AM
|
|
|
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>
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|