Technique for selectively formatting data in a PowerShell pipeline and output as HTML

Posted by halr9000 on Stack Overflow See other posts from Stack Overflow or by halr9000
Published on 2010-12-30T01:06:20Z Indexed on 2011/01/06 15:53 UTC
Read the original article Hit count: 211

Filed under:
|
|
|

Say that you want to do some fancy formatting of some tabular output from powershell, and the destination is to be html (either for a webserver, or to be sent in an email). Let's say for example that you want certain numeric values to have a different background color. Whatever. I can think of two solid programmatic ways to accomplish this: output XML and transform with XSLT, or output HTML and decorate with CSS.

XSLT is probably the harder of the two (I say that because I don't know it), but from what little I recall, it has the benefit of bring able to embed the selection criteria (xpath?) for aforementioned fancy formatting. CSS on the other hand needs a helping hand. If you wanted a certain cell to be treated specially, then you would need to distinguish it from its siblings with a class, id, or something along those lines. PowerShell doesn't really have a way to do that natively, so that would mean parsing the HTML as it leaves convertto-html and adding, for example, a "emphasis" class:

<td class="emphasis">32MB</td>

I don't like the idea of the required text parsing, especially given that I would rather be able to somehow emphasize what needs emphasizing in Powershell before it hits HTML.

Is XSLT the best way? Have suggestions for how to markup the HTML after it leaves convertto-html or ideas of a different way?

© Stack Overflow or respective owner

Related posts about html

Related posts about css