Finding HREFs that contain specific folder in path

craig.haiss's Avatar

craig.haiss

08 May, 2015 06:33 PM

Hi!

I'm trying to accomplish two things in the attached XSLT format. First, I'm looking for text references that point to our website. Second, I want to find HREFs that include specific folders from our website. The first part works, the second does not. Instead, it lists all pages from the index block, not just those containing HREFs with the target folder. Only a few pages actually include the /products/ folder specified in the format.

Can you help me fix the XSLT so that it finds the HREFs?

Thanks!

  1. Support Staff 1 Posted by Tim on 08 May, 2015 07:34 PM

    Tim's Avatar

    Hi Craig,

    I haven't had much time to dig into this, but I did take a quick peek at your Format and I'm wondering what happens if you change this line:

    <xsl:if test="//a[contains(@href,'/products/')]">
    
    to this:
    <xsl:if test="a[contains(@href,'/products/')]">
    
    Can you give that a shot and let me know if that changes the behavior?

    If you still have trouble, please attach the Index Block that you are transforming along with your expected output and the actual output.

    Thanks!

  2. 2 Posted by craig.haiss on 13 May, 2015 08:33 PM

    craig.haiss's Avatar

    Thanks for taking time to look at this, Tim.

    I made the suggested change (from "//a" to just "a"). After that, instead of listing all content blocks as containing /product/ links, the page listed no content blocks. It should list only content blocks that have a hyperlink pointing to "/products/".

    I'm attaching two files. The first is the Index block. The second is what I'd like the resulting table to look like, with the text in the "Title of content block" column hyperlinked to the actual blocks in the CMS.

    Thanks so much for your help!

  3. 3 Posted by Ryan Griffith on 02 Jun, 2015 07:22 PM

    Ryan Griffith's Avatar

    Hi Craig,

    Tim will be on vacation for the week so I wanted to follow up here.

    After taking a look at your Format, I believe what you will want to do is adjust your <xsl:if> from:

    <xsl:if test="//a[contains(@href,'/products/')]">
    

    to:

    <xsl:if test=".//a[contains(@href,'/products/')]">
    

    When using //a, the XPath will return all <a> elements at any level, whereas .//a will return all <a> elements at any level starting at the current node.

    Please let me know if you have any questions or if the code adjustment does not work out.

    Thanks!

  4. 4 Posted by craig.haiss on 03 Jun, 2015 08:52 PM

    craig.haiss's Avatar

    Awesome, that worked perfectly! Thanks so much for helping me sort this out. I'll mark this one as 'closed.'

  5. craig.haiss closed this discussion on 03 Jun, 2015 08:52 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac