Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Can you style XMLwith CSS to display tag attributes?

by BrowserUk (Patriarch)
on Jun 11, 2015 at 00:13 UTC ( [id://1129955]=perlquestion: print w/replies, xml ) Need Help??

BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:

I have a large XML file containing programming api information. Reading it is a pain.

But it is pure XML (not HTML) and thus contains no styling, so I had the notion that if I applied a little styling I could view it in my browser instead of my editor and the <TAG>s would disappear, making it easier to read. The problem is, that much of the salient information is details in tag attributes; and that disappears with the tags once styled. Is there a solution to this that doesn't involve reformatting the whole XML document?

An example of the XML:

<intrinsic tech='MMX' rettype='__m64' name='_m_from_int64'> <type>Integer</type> <CPUID>MMX</CPUID> <category>Convert</category> <parameter varname='a' type='__int64'/> <description>Copy 64-bit integer "a" to "dst".</description> <operation> dst[63:0] := a[63:0] </operation> <instruction name='movq' form='mm, r64'/> <header>mmintrin.h</header> </intrinsic>

Specifically, is there any way to style that so that the rettype and name fields are displayed?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

Replies are listed 'Best First'.
Re: Can you style XMLwith CSS to display tag attributes?
by Anonymous Monk on Jun 11, 2015 at 01:40 UTC

    It's possible since CSS2, although in the long run you'd probably be happier with XSLT or a manual transform, e.g. XML::Twig.

    * { display: block; } type:before { content: "Type: " } CPUID:before { content: "CPUID: " } /* etc */ intrinsic:before { content: "intrinsic name=" attr(name) ", rettype=" attr(rettype) }

      That works perfectly for my purpose. Thank you.

      although in the long run you'd probably be happier with XSLT or a manual transform, e.g. XML::Twig.

      Not so much. The source (from the Intel website) seems to change pretty regularly -- the current version was update 26th May, 2015 -- so I'd rather just have a local style sheet that will allow me to read it once I download it, rather than have to go through a bunch of manipulations each time it changes.

      I'm not trying to make it pretty; just readable; and only for me.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
      In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
        That can all bhe automated: one Perl script to download the file at regular intervals; transform it through XSLT and save it on your hard-disk as HTML: ready for you to double-click it and read it in your browser.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        My blog: Imperial Deltronics
Re: Can you style XMLwith CSS to display tag attributes?
by RichardK (Parson) on Jun 11, 2015 at 09:20 UTC

    You can add a stylesheet directive to an xml file, see http://www.w3.org/TR/xml-stylesheet/ or google around for some tutorials.

    It works for me when opening the file in firefox, the top of your xml then looks like this :-

    <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/css" href="view.css"?> ...

      That just dumps the content (minus tags including attributes) to the screen as a big unstructured mess? Not at all what I sought.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
      In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

        Well, you can get very creative with your css definition, but if that's not doing it for you then there's always XSLT -- good luck with that :)

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1129955]
Approved by stevieb
Front-paged by stevieb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-19 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found