[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-1-en-105":3,"doc-seo-195309-105":53,"doc-detail-195309-en":126},{"code":4,"msg":5,"data":6},0,"success",[7,14,19,24,29,34,39,44,49],{"id":8,"doc_module":9,"doc_module_name":10,"category_name":11,"show_sort_weight":12,"slug":13},11,1,"Template","Presentations",90,"presentations",{"id":15,"doc_module":9,"doc_module_name":10,"category_name":16,"show_sort_weight":17,"slug":18},12,"Resumes",80,"resumes",{"id":20,"doc_module":9,"doc_module_name":10,"category_name":21,"show_sort_weight":22,"slug":23},14,"Invoices",70,"invoices",{"id":25,"doc_module":9,"doc_module_name":10,"category_name":26,"show_sort_weight":27,"slug":28},15,"Posters",60,"posters",{"id":30,"doc_module":9,"doc_module_name":10,"category_name":31,"show_sort_weight":32,"slug":33},16,"Social Media",50,"social-media",{"id":35,"doc_module":9,"doc_module_name":10,"category_name":36,"show_sort_weight":37,"slug":38},17,"Forms",40,"forms",{"id":40,"doc_module":9,"doc_module_name":10,"category_name":41,"show_sort_weight":42,"slug":43},18,"Letters",30,"letters",{"id":45,"doc_module":9,"doc_module_name":10,"category_name":46,"show_sort_weight":47,"slug":48},21,"Paper Templates",5,"papers-templates",{"id":50,"doc_module":9,"doc_module_name":10,"category_name":51,"show_sort_weight":4,"slug":52},158,"General","general-158",{"code":4,"msg":54,"data":55},"ok",{"site_id":56,"language":57,"slug":58,"title":59,"keywords":60,"description":61,"schema_data":62,"social_meta":119,"head_meta":121,"extra_data":123,"updated_unix":125},105,"en","using-types-to-make-your-stylesheets-more-robust","Using types to make your stylesheets more robust","","The document explains how using XSLT “as” attributes and strong type declarations can make stylesheets more robust and reliable. It walks through scenario-based transformations where input XML with varying structure is converted into HTML. Examples demonstrate enforcing cardinalities, handling different node types such as elements, attributes, and text nodes, and improving function signatures. The final version outputs cleaner, better-formatted results.",{"@graph":63,"@context":118},[64,80,101],{"@type":65,"itemListElement":66},"BreadcrumbList",[67,71,74,77],{"item":68,"name":69,"@type":70,"position":9},"https://docshare.wps.com","Home","ListItem",{"item":72,"name":10,"@type":70,"position":73},"https://docshare.wps.com/template/",2,{"item":75,"name":51,"@type":70,"position":76},"https://docshare.wps.com/template/general/",3,{"item":78,"name":59,"@type":70,"position":79},"https://docshare.wps.com/template/using-types-to-make-your-stylesheets-more-robust/195309/",4,{"url":78,"name":59,"@type":81,"image":82,"author":87,"headline":59,"publisher":90,"fileFormat":93,"inLanguage":57,"description":61,"dateModified":94,"datePublished":95,"encodingFormat":93,"isAccessibleForFree":96,"interactionStatistic":97},"DigitalDocument",{"url":83,"@type":84,"width":85,"height":86},"https://docshare.wps.com/thumbnails/using-types-to-make-your-stylesheets-more-robust/195309.png","ImageObject",442,249,{"name":88,"@type":89},"Theodora","Person",{"url":68,"name":91,"@type":92},"DocShare","Organization","application/pdf","2026-09-21","2026-09-03",true,{"@type":98,"interactionType":99,"userInteractionCount":73},"InteractionCounter",{"@type":100},"ViewAction",{"@type":102,"mainEntity":103},"FAQPage",[104,110,114],{"name":105,"@type":106,"acceptedAnswer":107},"How do type annotations improve an XSLT stylesheet’s robustness?","Question",{"text":108,"@type":109},"By using “as” attributes to declare parameter and return types, the stylesheet becomes more predictable when transforming XML data. This helps enforce expectations about values and structures during processing.","Answer",{"name":111,"@type":106,"acceptedAnswer":112},"What does Scenario 1 focus on?",{"text":113,"@type":109},"Scenario 1 demonstrates using types to enforce cardinalities. It starts from sample book input documents and shows how stricter typing affects the transformation behavior.",{"name":115,"@type":106,"acceptedAnswer":116},"How does the final XSLT version differ in output quality?",{"text":117,"@type":109},"The document states that the results shown in Figure 3 look much better in the final Scenario 1 XSLT. It achieves improved formatting by refining how functions and selections handle the input structure.","https://schema.org",{"og:url":78,"og:type":120,"og:title":59,"og:site_name":91,"og:description":61},"article",{"robots":122,"canonical":78},"index,follow",{"doc_id":124,"site_id":56},195309,1788447309,{"code":4,"msg":5,"data":127},{"doc_id":124,"user_id":128,"nickname":88,"user_avatar":129,"doc_module":9,"category_id":50,"category_name":51,"doc_title":59,"doc_description":61,"doc_content":130,"file_id":131,"file_url":132,"file_type":133,"file_size":134,"view_count":73,"is_deleted":4,"is_public":9,"is_downloadable":9,"audit_status":9,"page_count":135,"language":136,"language_code":57,"site_id":56,"html_lang":57,"table_of_contents":137,"faqs":138,"seo_title":139,"seo_description":61,"update_tm":125,"read_time":140},687197207919,"https://ap-avatar.wpscdn.com/avatar/a000253d6f5f7c60be?x-image-process=image/resize,m_fixed,w_180,h_180&k=1779446848396160552","| Data type name | Description | Example(s) |\n| --- | --- | --- |\n| string | Any text string | abc, this is a string |\n| integer | An integer of any size | 1, 2 |\n| decimal | A decimal number | 1.2, 5.0 |\n| double | A double-precision floating point number | 1.2, 5.0 |\n| date | A date, in YYYY-MM-DD format | 2009-12-25 |\n| time | A time, in HH:MM:SS format | 12:05:04 |\n| boolean | A true/false value | true, false |\n| anyAtomicType | A value of any of the simple types | a string, 123, false, 2009-12-25 |\n\n\n| Sequence type | Description |\n| --- | --- |\n| element() | Any element |\n| element(book) | Any element named book |\n| attribute() | Any attribute |\n| attribute(isbn) | Any attribute named isbn |\n| text() | Any text node |\n| node() | A node of any kind (element, attribute, text node, etc. ) |\n| item() | Either a node of any kind or an atomic value of any kind (e.g. a string, integer, etc.) |\n\n\n| Occurrence indicator | Description |\n| --- | --- |\n| * | Zero to many |\n| ? | Zero to one |\n| + | One to many |\n| (no occurrence indicator) | One and only one |\n\n| Using types to make your stylesheets more robust\u003Cbr>You may be wondering how the use of as attributes improves your stylesheets. Let's look at a couple of examples. All of the examples in this article can be downloaded as a zip file.\u003Cbr>Scenario 1: Using types to enforce cardinalities\u003Cbr>Example 1 shows an input document that contains two books.\u003Cbr>Example 1. Sample book input, books.xml |\n| --- |\n| \u003Cbooks\u003Cbr>xmlns=\"[http://www.datypic.com/books/ns](http://www.datypic.com/books/ns)\">\u003Cbook>\u003Cbr>\u003Ctitle>The East-West House: Noguchi's Childhood in Japan\u003C/title>\u003Cauthor>\u003Cbr>\u003Cperson>\u003Cbr>\u003Cfirst>Christy\u003C/first>\u003Cbr>\u003Clast>Hale\u003C/last>\u003C/person>\u003C/author>\u003Cprice>9 . 95\u003C/price>\u003Cbr>\u003Cdiscount>1 . 95\u003C/discount>\u003C/book>\u003Cbr>\u003Cbook>\u003Cbr>\u003Ctitle>Buckminster Fuller and Isamu Noguchi: Best of Friends\u003C/title>\u003Cauthor>\u003Cbr>\u003Cperson>\u003Cbr>\u003Cfirst>Shoji\u003C/first>\u003Cbr>\u003Clast>Sadao\u003C/last>\u003C/person>\u003C/author>\u003Cprice>65 .00\u003C/price>\u003Cbr>\u003Cdiscount>5 .00\u003C/discount>\u003C/book>\u003Cbr>\u003C/books> |\n| Example 2 is a stylesheet that will transform book input into HTML. |\n\n| Example 2. Scenario 1 XSLT, original version |  |\n| --- | --- |\n| \u003Cxsl:stylesheet version=\"2 .0\"\u003Cbr>xmlns:xsl=\"[http://www.w3.org/1999/XSL/Transform](http://www.w3.org/1999/XSL/Transform) \"\u003Cbr>xmlns:dtyf=\"[http://www.datypic.com/functions](http://www.datypic.com/functions) \"\u003Cbr>xpath-default-namespace=\"[http://www.datypic.com/books/ns](http://www.datypic.com/books/ns)\">\u003Cxsl:output method=\"html\"/>\u003Cbr>\u003Cxsl:template match=\"books\">\u003Chtml>\u003Cbr>\u003Cbody>\u003Cbr>\u003Ctable border=\"1\">\u003Cbr>\u003Cxsl:apply-templates/>\u003Cbr>\u003C/table>\u003Cbr>\u003C/body>\u003Cbr>\u003C/html>\u003Cbr>\u003C/xsl:template>\u003Cbr>\u003Cxsl:template match=\"book\">\u003Ctr> |  |\n| \u003Ctd>\u003Cxsl:value-of\u003Cbr>\u003Ctd>\u003Cxsl:value-of\u003Cbr>\u003Ctd>\u003Cxsl:value-of \u003C/tr>\u003Cbr>\u003C/xsl:template> | select=\"title\"/>\u003C/td>\u003Cbr>select=\"dtyf:format-person-name(author/person)\"/>\u003C/td> select=\"price\"/>\u003C/td> |\n| \u003Cxsl:function name=\"dtyf:format-person-name\">\u003Cxsl:param name=\"person\"/>\u003Cbr>\u003Cxsl:value-of select=\"$person/last\"/>\u003Cxsl:text>, \u003C/xsl:text>\u003Cbr>\u003Cxsl:value-of select=\"$person/first\"/>\u003C/xsl:function>\u003Cbr>\u003C/xsl:stylesheet> |  |\n\n| Example 3. More varied input document, morebooks.xml |\n| --- |\n| \u003Cbooks\u003Cbr>xmlns=\"[http://www.datypic.com/books/ns](http://www.datypic.com/books/ns)\">\u003Cbook>\u003Cbr>\u003Ctitle>Isamu Noguchi: Sculptural Design\u003C/title>\u003Cauthor>\u003Cbr>\u003Cinstitution>Vitra Design Museum\u003C/institution>\u003Cbr>\u003C/author>\u003Cprice>125 .00\u003C/price>\u003C/book>\u003Cbr>\u003Cbook>\u003Cbr>\u003Ctitle>The East-West House: Noguchi's Childhood in Japan\u003C/title>\u003Cauthor>\u003Cbr>\u003Cperson>\u003Cbr>\u003Cfirst>Christy\u003C/first>\u003Cbr>\u003Clast>Hale\u003C/last>\u003C/person>\u003C/author>\u003Cprice>9 . 95\u003C/price>\u003Cbr>\u003Cdiscount>1 . 95\u003C/discount>\u003C/book>\u003Cbr>\u003Cbook>\u003Cbr>\u003Ctitle>Buckminster Fuller and Isamu Noguchi: Best of Friends\u003C/title>\u003Cbr>\u003Cauthor>\u003Cbr>\u003Cperson>\u003Cbr>\u003Cfirst>Shoji\u003C/first>\u003Cbr>\u003Clast>Sadao\u003C/last>\u003C/person>\u003C/author>\u003Cprice>65 .00\u003C/price>\u003Cbr>\u003Cdiscount>5 .00\u003C/discount>\u003C/book>\u003Cbr>\u003Cbook>\u003Cbr>\u003Ctitle>Isamu Noguchi and Modern Japanese Ceramics: A Close Embrace of the Earth\u003C/title>\u003Cauthor>\u003Cbr>\u003Cperson>\u003Cbr>\u003Cfirst>Louise\u003C/fir","cbCaifTbkZd6bbF8","https://ap.wps.com/l/cbCaifTbkZd6bbF8","pdf",261899,19,"English","# Using types to make your stylesheets more robust\n## Scenario 1: Enforce cardinalities\n## Example transformations and function return types","[{\"question\":\"How do type annotations improve an XSLT stylesheet’s robustness?\",\"answer\":\"By using “as” attributes to declare parameter and return types, the stylesheet becomes more predictable when transforming XML data. This helps enforce expectations about values and structures during processing.\"},{\"question\":\"What does Scenario 1 focus on?\",\"answer\":\"Scenario 1 demonstrates using types to enforce cardinalities. It starts from sample book input documents and shows how stricter typing affects the transformation behavior.\"},{\"question\":\"How does the final XSLT version differ in output quality?\",\"answer\":\"The document states that the results shown in Figure 3 look much better in the final Scenario 1 XSLT. It achieves improved formatting by refining how functions and selections handle the input structure.\"}]","Using types to make your stylesheets more robust | PDF",7]