for-each i for-each
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<!-- these values is written using serverside modeling -->
<xsl:variable name="selected_profile_id" select="1"/>
<xsl:variable name="selected_preference_id" select="1"/>
<xsl:variable name="TEMP_PREF_XML"
select="document('Preferences.xml')/Preferenceset[//PreferenceSet/@profile_id=$selected_profile_id]"/>
<xsl:variable name="Preferences_XML"
select="$TEMP_PREF_XML[//PreferenceSet/@id=$selected_preference_id]"/>
<!-- end variables -->
<xsl:template match="/">
<xsl:for-each select="$Preferences_XML//Element">
<xsl:variable name="type" select="./type"/>
<xsl:variable name="subtype" select="./subtype"/>
<xsl:variable name="model" select="./model"/>
<b>Variable: </b><xsl:value-of select="$type" /> : <xsl:value-of select="$subtype" /> : <xsl:value-of select="$model" />
<br />
<xsl:for-each select="/PictureDatabase/Picture">
<xsl:value-of select="."/>
</xsl:for-each>
<hr/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
===============================================================
===============================================================
Dette stylesheet bliver applied på en XML, problemet er at jeg i den inderste for-each gerne vil finde ting, baseret på min variable...
jeg vil fx gerne have "filefeature/title" ud
===============================================================
XML dokumentet som Stylesheetet skal transform :
===============================================================
<PictureDatabase xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\Dokumenter\Altova Projects\PictureDatabase.xsd">
<Picture id="1" profile_id="1">
<filefeatures>
<title>My Saleen</title>
<filesize>2048000</filesize>
<filename>pict1234.jpg</filename>
<fileurl>htttp://someurl.com/pictures/1/</fileurl>
<creation_date>2006-04-01T12:00:00</creation_date>
<caption_date>2006-04-01T12:00:00</caption_date>
<modified_date>2006-04-02T13:00:00</modified_date>
</filefeatures>
<exifdata>
<PictureWidth>3008</PictureWidth>
<PictureHeight>2000</PictureHeight>
<BitsPerPixel>24</BitsPerPixel>
</exifdata>
<contentdescription>
<direction>landscape</direction>
<Composisition>horizontal center</Composisition>
<ElementalDescription>
<Element x1="300" x2="2700" y1="300" y2="1500">
<type>Vehicle</type>
<subtype>Car</subtype>
<model>Saleen</model>
<color avgBlue="220" avgGreen="5" avgRed="5"/>
</Element>
</ElementalDescription>
</contentdescription>
</Picture>
<Picture id="2" profile_id="2">
<filefeatures>
<title>Flower</title>
<filesize>2048000</filesize>
<filename>pict1511.jpg</filename>
<fileurl>htttp://someurl.com/pictures/2/</fileurl>
<creation_date>2006-05-09T12:00:00</creation_date>
<caption_date>2006-05-09T12:00:00</caption_date>
<modified_date>2006-05-09T12:00:00</modified_date>
</filefeatures>
<exifdata>
<PictureWidth>3008</PictureWidth>
<PictureHeight>2000</PictureHeight>
<BitsPerPixel>8</BitsPerPixel>
</exifdata>
<contentdescription>
<direction>portrait</direction>
<Composisition>diagonal</Composisition>
<ElementalDescription>
<Element x1="300" x2="1800" y1="100" y2="2500">
<type>Flora</type>
<subtype>Flower</subtype>
<model></model>
<color avgBlue="240" avgGreen="230" avgRed="15"/>
</Element>
</ElementalDescription>
</contentdescription>
</Picture>
<Collection id="1" profile_id="1">
<modified_date>2006-06-14T12:00:00</modified_date>
<creation_date>2006-06-01T12:00:00</creation_date>
<collection_name>Martins Collection</collection_name>
<Pictures>
<picture_id>1</picture_id>
</Pictures>
</Collection>
</PictureDatabase>