tags:

views:

68

answers:

1

Basically, I have some xslt that I have written and I want to migrate the same functionality to C#. I know I have to use XPath and such, but I am having trouble properly accessing the right nodes and attributes.

Here is the functionality I want to translate:

<xsl:for-each select="$mediaNode/node">
    <xsl:variable name="mediaNodeName" select="translate(@nodeName, '_', '')"/>
    <xsl:if test="Exslt.ExsltStrings:lowercase(substring($mediaNodeName, 1, $MainNodeNameLength)) = Exslt.ExsltStrings:lowercase($MainNodeName)">
        <!-- do stuff with @nodeName and such -->
    </xsl:if>
</xsl:for-each>

This XSLT template takes $galleryOf as a parameter which is an int of the umbraco xml nodeid and it takes $MainNodeName which is the text that I will be comparing inside that for loop.

I just need some help figuring out how to get at each of the nodes in the fashion that I did here but using C#.

This is what I have been working with:

    public static string GetGalleryById(int mediaNodeID, string filename)
    {
        string results = "";

        // if node exists then look for images
        if (mediaNodeID > 0)
        {
            // get a node iterator for the media node section passed in
            XPathNodeIterator xni = umbraco.library.GetMedia(mediaNodeID, false);
            xni = xni.Current.SelectChildren("node", "");

            // loop through all of the images in the folder to find ones that match the @param filename
            while (xni.MoveNext())
            {
                string currentName =
                currentName = currentName.Replace("_", "");


            //    // if there's a match then get build the html and add to results
            //    if (currentName.Substring(1, filename.Length).ToLower() == filename.ToLower())


            return results;

        }
        // otherwise, return no result.
        else
        {
            return "Nothing to see here...";
        }
    }

Thanks!

A: 

I ended up just using XPathNodeIterator to select the nodes that I wanted, and from there I just used a foreach loop to go through each node.

samandmoore