Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML with cross references 1

Status
Not open for further replies.

Miros

Programmer
Jan 27, 2001
506
US
In my XML input file (output from another program over which I have no control), I have package nodes that look like this:
Code:
  <packages ptype="ClothingMesh" isOrphan="false" isBroken="false" ptype2="3">
    <filename>MESH_afTop_34Dn_Tshirt.package</filename>
    <title />
    <description />
    <filesize>405103</filesize>
    <lastmodified>2007-05-17T00:00:00.0000000-04:00</lastmodified>
    <subfolder>\Warlokk</subfolder>
    <polyCount>0</polyCount>
    <md5hash>2F48E16A185E5D2291EBEA5F43FA4AB0</md5hash>
    <catalogPlacement />
    [red]<tgis tgi_type="FC6EB1F7" tgi_group="1C050000" tgi_instance2="B1BF1329" tgi_instance="FF121E17" />[/red]
  </packages>

Each "ClothingMesh" package node has one or more "ClothingRecolour" package nodes associated with it, identified by the <tgis> node and its attributes.
Code:
  <packages ptype="ClothingRecolour" isOrphan="false" isBroken="false" ptype2="2">
    <filename>psaftop_t_blank.package</filename>
    <title>aftoptshirt_whitevneck </title>
    <description>T-Shirt Top Mesh Only by The Pearl</description>
    <filesize>282441</filesize>
    <lastmodified>2006-10-25T00:00:00.0000000-04:00</lastmodified>
    <subfolder>\simshost</subfolder>
    <polyCount>0</polyCount>
    <md5hash>6F26EB7F981CF490391322F11E63E148</md5hash>
    <catalogPlacement>Female Everyday </catalogPlacement>
    [red]<tgis tgi_type="FC6EB1F7" tgi_group="1C050000" tgi_instance2="B1BF1329" tgi_instance="FF121E17" />[/red]
  </packages>

I can extract the information I want about the ClothingMesh package nodes with this code:
Code:
	<xsl:template match="packages">
		<xsl:if test="@ptype = 'ClothingMesh'"> 
			<xsl:apply-templates select="subfolder"/>\<xsl:apply-templates select="filename"/><br />
		</xsl:if>
	</xsl:template>
    
	<xsl:template match="subfolder">		
		<xsl:apply-templates/>
	</xsl:template>
		
	<xsl:template match="filename">
		<xsl:apply-templates/>
	</xsl:template>

Is there a way to also list the subfolder and filename nodes for the "ClothingRecolour" package nodes with matching tgis nodes? As I said, there will be at least one, and possibly many recolors for each mesh. Output should look something like this:
Code:
\Warlokk\MESH_afTop_34Dn_Tshirt.package<br />
<ul>
<li>\simshost\psaftop_t_blank.package<br /></li>
<li>\simshost\psaftop_t_blank2.package<br /></li>
<li>\simshost\psaftop_t_blank3.package<br /></li>
<li>\simshost\psaftop_t_blank4.package<br /></li>
</ul>
 
[1] One way is to substantiate the major <xsl:if></xsl:if> block. Like this.
[tt]
<xsl:template match="packages">
<xsl:if test="@ptype = 'ClothingMesh'">
<xsl:apply-templates select="subfolder"/>\<xsl:apply-templates select="filename"/><br />
[blue]<xsl:if test="../packages[@ptype='ClothingRecolour' and tgis/@tgi_type=current()/tgis/@tgi_type]">
<ul>
<xsl:for-each select="../packages[@ptype='ClothingRecolour' and tgis/@tgi_type=current()/tgis/@tgi_type]">
<li>
<xsl:apply-templates select="subfolder"/>\<xsl:apply-templates select="filename"/>
</li>
</xsl:for-each>
</ul>
</xsl:if>[/blue]
</xsl:if>
</xsl:template>
[/tt]
[2] I do not put the additional <br /> inside the <li> above because it shouldn't be needed without a reason. You can put it there if there is a need.

[3] I take one conditional on the identification of tgis in the search, namely, tgi_type; if you need all the attributes being equal, just get them checked in the predicat by piling up more "and".
 
Perfect! Thanks much.

The line break was a remnant from before I put in the list construction, so no, it's not needed.

There's a few other "ptype" values that can be check, but I can just put them on with the other attributes.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top