• Structured Authoring, XSLT

    Posted on August 13th, 2009

    Written by douglaspaulwade

    Tags

    Using XSLT, I want to display some examples, however, not show you the original text. My sample file is a real-world example, but the content is a distraction. This simple transformation will convert all of the text nodes (document text) to x’s. During the transformation, the XSLT stylesheet will convert, all the capital, lowercase letters and the numbers to the lower case ‘x’. It will leave the punctuation alone, and the elements’ attributes are left unchanged.

    Here is a sample snippet of the input file of S1000D Issue 3, XML:

    <?xml version="1.0" encoding="UTF-8"?>

    <dmodule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:dc="http://www.purl.org/dc/elements/1.1/"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     xsi:noNamespaceSchemaLocation="http://www.s1000d.org/S1000D_3-0/xml_schema_master/dm/faultSchema.xsd">

     <idstatus>
     <dmaddres>
     <dmc>
     <avee>
     <modelic>AAA</modelic>
     <sdc>B</sdc>
     <chapnum>28</chapnum>
     <section>0</section>
     <subsect>0</subsect>
     <subject>00</subject>
     <discode>00</discode>
     <discodev>A</discodev>
     <incode>421</incode>
     <incodev>A</incodev>
     <itemloc>A</itemloc>
     </avee>
     </dmc>
     <dmtitle>
     <techname>FUEL LEAK IN FORWARD COMPARTMENT AREA</techname>
     <infoname>OBSERVED FAULT PROCEDURE</infoname>
     </dmtitle>
     <issno issno="001" type="new"/>
     <issdate day="01" month="01" year="2009"/>
     </dmaddres>
     <status>
     <security/>
     <rpc/>
     <orig/>

    Here is the transformation stylesheet:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     exclude-result-prefixes="xs"
     version="2.0">

     <!– Use indent yes for development, no for production –>
     <xsl:output method="xml" indent="yes"/>

     <!–
     Template match all items, except
     SGML Notations and Entities e.g., illustrations.
     –>

     <xsl:template match="@*|element()|comment()|processing-instruction()" mode="#all">
     <xsl:copy>
     <xsl:apply-templates select="@*|node()" mode="#current"/>
     </xsl:copy>
     </xsl:template>

     <!– Using the replace function,
     context is: string, pattern, replacement string–>

     <xsl:template match="text()">
     <xsl:value-of select="replace(.,’[a-zA-Z0-9]‘,’x')"/>
     </xsl:template>
    </xsl:stylesheet>

    Here is the result.s tree (a snippet).

    <?xml version="1.0" encoding="UTF-8"?>
    <dmodule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:dc="http://www.purl.org/dc/elements/1.1/"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     xsi:noNamespaceSchemaLocation="http://www.s1000d.org/S1000D_3-0/xml_schema_master/dm/faultSchema.xsd">

     <idstatus>
     <dmaddres>
     <dmc>
     <avee>
     <modelic>xxx</modelic>
     <sdc>x</sdc>
     <chapnum>xx</chapnum>
     <section>x</section>
     <subsect>x</subsect>
     <subject>xx</subject>
     <discode>xx</discode>
     <discodev>x</discodev>
     <incode>xxx</incode>
     <incodev>x</incodev>
     <itemloc>x</itemloc>
     </avee>
     </dmc>
     <dmtitle>
     <techname>xxxx xxxx xx xxxxxxx xxxxxxxxxxx xxxx</techname>
     <infoname>xxxxxxxx xxxxx xxxxxxxxx</infoname>
     </dmtitle>
     <issno issno="001" type="new"/>
     <issdate day="01" month="01" year="2009"/>
     </dmaddres>
     <status>
     <security/>
     <rpc/>
     <orig/>

    This entry was posted on Thursday, August 13th, 2009 at 6:50 am and is filed under Structured Authoring, XSLT. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
  • 0 Comments

    Take a look at some of the responses we have had to this article.

  • Leave a Reply

    Let us know what you thought.

  • Name(required):

    Email(required):

    Website:

    Message: