views:

104

answers:

1

To use images in wpf you can define:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;

<BitmapImage x:Key="ImageFunTime"  UriSource="../Resources/Images/ImageFunTime.png" />

...

Then in app somewhere you can:

var img = (ImageSource)positionsTab.TryFindResource("ImageFunTime");

How can I achieve the same thing with an embedded Xslt file? That is, whats the syntax in the resource dictionary, as its obviously not an Bitmap image...

TIA

A: 

How can I achieve the same thing with an embedded Xslt file?

Answers:

  1. None of the Microsoft's XSLT processor supports embedded XSLT stylesheets. You will need a complete, XSLT-only file for your XSLT stylesheet.

  2. In XSLT one uses the <xsl:key> instruction and the key() function for efficient selecting nodes by some string value, that identifies them uniquely.

This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 >
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:key name="UriSourceByKey"
  match="@UriSource" use="../@x:Key"/>

 <xsl:variable name="vImageFunTime"
  select="key('UriSourceByKey', 'ImageFunTime')"/>

 <xsl:template match="/">
  <xsl:value-of select="$vImageFunTime"/>
 </xsl:template>
</xsl:stylesheet>

when applied on this XML document:

<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;

  <BitmapImage x:Key="ImageFunTime"  UriSource="../Resources/Images/ImageFunTime.png" />
</ResourceDictionary>

produces the wanted result:

../Resources/Images/ImageFunTime.png
Dimitre Novatchev