Replace text in XSL using wildcards

Posted by JosephThomas on Stack Overflow See other posts from Stack Overflow or by JosephThomas
Published on 2012-06-22T17:05:59Z Indexed on 2012/06/23 15:16 UTC
Read the original article Hit count: 196

Filed under:
|

This is similar to an earlier problem I was having which you guys solved in less than a day.

I am working with XML files that are generated by a digital video camera. The camera allows the user to save all of the camera's settngs to an SD card so that the settings can be recalled or loaded into another camera. The XSL stylesheet I am writing will allow users to view the camera's settings, as saved to the SD card in a web browser.

While most of the values in the XML file -- as formatted by my stylesheet -- make sense to humans, some do not. What I would like to do is have the stylesheet display text that is based on the value in the XML file but more easily understood by humans.

A typical value that can be written to the XML file is "_23_970" which represents the camera's frame rate. This would be better displayed as 23.970 (or 023.970). The first underscore is a sort of place holder to make a space for values over 099.999. The second underscore, obviously represents the decimal.

My previous (similar) question involved replacing predictable text, and the solution was matching templates. In this case, however, the camera can be set at any one of 119,999 frame rates (I think I did that math correctly).

The approach, I would guess, is to pass a value to the displayed webpage that keeps the numeric values (each digit), replaces the second underscore with a decimal, and replaces the first underscore with either an nbsp or a zero (whichever is easier). If the first character in the string is a "1" (the camera can run at frame rates up to 120.000) then the one should be passed on to the page displayed by the stylesheet.

I have read other posts here regarding wildcards, but couldn't find one that answered this question.

EDIT: Sorry for leaving out important info. I fared better on my first try at asking a question! I guess I got complacent. Anyhow . . .

I should have shown you the code that displays the text in the XSL file as is:

<tr>
  <xsl:for-each select="Settings/Groups/Recording">
    <tr><td class="title_column">Frame Rate</td><td><xsl:value-of select="RecOutLinkSpeed"/></td></tr>
   </xsl:for-each>
</tr>

I should also have given you the URL for the sample file I have been working with: http://josephthomas.info/Alexa/Setup_120511_140322.xml

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xslt