# XSLT and autoindex XML output: conditionally transform XML only when it's autoindex output?

**URL:** <https://www.ruby-forum.com/t/xslt-and-autoindex-xml-output-conditionally-transform-xml-only-when-its-autoindex-output/244148>\
**Category:** NGINX\
**Created:** [February 26, 2016, 8:28pm UTC](https://www.ruby-forum.com/t/xslt-and-autoindex-xml-output-conditionally-transform-xml-only-when-its-autoindex-output/244148 "2016-02-26T20:28:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [February 26, 2016, 8:28pm UTC](https://www.ruby-forum.com/t/xslt-and-autoindex-xml-output-conditionally-transform-xml-only-when-its-autoindex-output/244148/1 "2016-02-26T20:28:03Z")

</div>

Hi,

The documentation said it’s possible to transform XML dirlistings into  
XHTML in order to customize what they look like, so I did one that makes  
them look like lighttpd’s:

> <https://gist.github.com/wilhelmy/5a59b8eea26974a468c9>

This works fine, but does anybody know how I apply the XSLT only  
to transform directory indexes but not other XML files that might be  
around? Currently, the way this config works is that all XML files are  
being transformed by this stylesheet.

The config looks like this:

> <https://gist.github.com/wilhelmy/5a59b8eea26974a468c9#file-nginx-snippet-conf>

Thanks and best regards,

Moritz

---

<div class="post-metadata">

**Author:** ![Moritz\_Wilhelmy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e56c9b/32.png) [@Moritz\_Wilhelmy](https://www.ruby-forum.com/u/Moritz_Wilhelmy)\
**Post date:** [February 26, 2016, 9:23pm UTC](https://www.ruby-forum.com/t/xslt-and-autoindex-xml-output-conditionally-transform-xml-only-when-its-autoindex-output/244148/2 "2016-02-26T21:23:33Z")

</div>

> to transform directory indexes but not other XML files that might be  
> around? Currently, the way this config works is that all XML files are  
> being transformed by this stylesheet.
> 
> The config looks like this:  
> [make nginx dirlistings look like lighttpd's through the magic of xslt-transforming xml dirlistings. I don't even. · GitHub](https://gist.github.com/wilhelmy/5a59b8eea26974a468c9#file-nginx-snippet-conf)

Cannot check with xslt right now, but autoindex should works with this  
setup:

```
    root /opt/www;

    location / {
        try_files $uri @autoindex;
    }

    location @autoindex {
        autoindex on;
    }

```

Try to add xslt and xml directives in @autoindex location.

---

<div class="post-metadata">

**Author:** ![Moritz\_Wilhelmy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e56c9b/32.png) [@Moritz\_Wilhelmy](https://www.ruby-forum.com/u/Moritz_Wilhelmy)\
**Post date:** [February 26, 2016, 9:49pm UTC](https://www.ruby-forum.com/t/xslt-and-autoindex-xml-output-conditionally-transform-xml-only-when-its-autoindex-output/244148/3 "2016-02-26T21:49:50Z")

</div>

On Fri, Feb 26, 2016 at 23:22:54 +0300, Sergey B. wrote:

> > This works fine, but does anybody know how I apply the XSLT only  
> > root /opt/www;
> 
> ```
> location / {
> try_files $uri @autoindex;
> }
> 
> location @autoindex {
> autoindex on;
> }
> 
> ```
> 
> Try to add xslt and xml directives in @autoindex location.

Thanks, that seems to have done the trick. I’ve updated the gist to  
reflect my current working config, for anyone who’s curious.

Best regards,

Moritz

---

<div class="post-metadata">

**Author:** ![Moritz\_Wilhelmy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e56c9b/32.png) [@Moritz\_Wilhelmy](https://www.ruby-forum.com/u/Moritz_Wilhelmy)\
**Post date:** [March 5, 2016, 7:02pm UTC](https://www.ruby-forum.com/t/xslt-and-autoindex-xml-output-conditionally-transform-xml-only-when-its-autoindex-output/244148/4 "2016-03-05T19:02:37Z")

</div>

16c999e8c71134401a78d4d46435517b2271d6ac  
mojombo@16c999e8c71134401a78d4d46435517b2271d6ac  
mojombo/github-flavored-markdown@16c999e8c71134401a78d4d46435517b2271d6ac

Posted at Nginx Forum:

> **[Re: XSLT and autoindex XML output: conditionally transform XML only when it's...](https://forum.nginx.org/read.php?2,264890,265120#msg-265120)**
>
> Hi, The documentation said it's possible to transform XML dirlistings into XHTML in order to customize what they look like, so I did one that makes them look like lighttpd's: https://gist.github.com/wilhelmy/5a59b8eea26974a468c9 This works fine, but...
