SlideShare a Scribd company logo
1 of 29
Advanced XPath and XSLT Reuven Weiser, Suite Solutions
Who am I? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What is Suite Solutions? ,[object Object],[object Object],[object Object],[object Object],[object Object]
Main Topics ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What is XPath? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Main Topics ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Basic Structure ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Basic Example From commons.xsl: <xsl:template  match= &quot;*[contains(@class,' topic/fig ')]&quot; > <fo:block  xsl:use-attribute-sets= &quot;fig&quot;  id= &quot;{@id}&quot; > <xsl:apply-templates  select= &quot;*[not(contains(@class,' topic/title '))]&quot; /> <xsl:apply-templates  select= &quot;*[contains(@class,' topic/title ')]&quot; /> </fo:block> </xsl:template>
XPath Axes
XPath Abbreviations Expression Description Nodename Selects named node / Selects from the root node (start of expression) or the current node // Selects any descendant of the root node (start of expression) or the current node . Selects the current node .. Selects the parent of the current node @ Selects attributes * Wildcard – matches any element node() Matches any node of any kind [ ] Brackets that contain a predicate, which is used to find a specific node
Main Topics ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
List Numbering Goal: A client wants <ol>s in <fig>s to be uppercase-lettered, and sub-<ol>s to be lowercase-lettered Solution: <xsl:choose> <xsl:when  test= &quot;ancestor::*[contains(@class, ' topic/fig ')]&quot; > <xsl:number  format= &quot;A&quot; /> </xsl:when> <xsl:when  test= &quot;count(ancestor::*[contains(@class, ' topic/ol ')]) > 1&quot; > <xsl:number  format= &quot;a&quot; /> </xsl:when> <xsl:otherwise> <xsl:number/> </xsl:otherwise> </xsl:choose>
List Numbering Technique Note Instead of: <xsl:when  test= &quot;ancestor::*[contains(@class, ' topic/fig ')]&quot; > We could say: <xsl:when  test= &quot;ancestor::fig&quot; > But: That wouldn’t account for specialization!
Main Topics ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Trademarks and current() Goal: A client wants the trademark symbol to appear only on the first usage of each trademark Solution 1: <xsl:variable  name= &quot;trademark&quot;   select= &quot;@trademark&quot; /> <xsl:if  test= &quot;not(preceding::*[contains(@class, ' topic/tm ') and @trademark =  $trademark)&quot; > ... </xsl:if> Solution 2 (XPath 2.0): <xsl:if  test= &quot;not(preceding::*[contains(@class, ' topic/tm ') and @trademark =  current()/@trademark)&quot; > ... </xsl:if>
Main Topics ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Custom Functions Goal: A client wants to convert certain text strings to  Title Case Solution: <xsl:stylesheet  xmlns:xsl= &quot;http://www.w3.org/1999/XSL/Transform&quot;    xmlns:ss= &quot;http://www.suite-sol.com&quot;  version= &quot;1.1&quot; > <xsl:function  name= &quot;ss:first-upper-case&quot; >   <xsl:param   name= &quot;string&quot; />   <xsl:value-of  select= &quot;concat(upper-case(substring($string, 1, 1)),  lower-case(substring($string, 2)))&quot; /> </xsl:function>
Custom Functions Goal: A client to convert certain text strings to  Title Case Solution (continued): <xsl:function  name= &quot;ss:title-case&quot; >   <xsl:param   name= &quot;string&quot; />   <xsl:choose>   <xsl:when  test= &quot;contains($string, ' ')&quot; >   <xsl:value-of  select= &quot;concat(ss:first-upper-case(substring-before($string, ' ')), ' ',    ss:title-case(substring-after($string), ' '))&quot; />   </xsl:when>   <xsl:otherwise>   <xsl:value-of  select= &quot;ss:first-upper-case($string)&quot; />   </xsl:otherwise>   </xsl:choose> </xsl:function> <xsl:value-of  select= &quot;ss:title-case($stringToConvert)&quot; />
Main Topics ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
tokenize() Goal: A client wants to check for one outputclass (“border”) among many Challenge: There may also be a “borderless” outputclass, and the outputclass may appear among others (“border other”, “other border”, “otherA border otherB”) Solution 1: <xsl:if  test= &quot;(@outputclass = 'border') or starts-with(@outputclass, 'border ')  or contains(@outputclass, ' border ')  or (substring(@outputclass, string-length(@outputclass)-6, 7)= ' border')&quot; >   <xsl:attribute  name= &quot;border&quot; > 1pt solid black </xsl:attribute> </xsl:if>
tokenize() Goal: A client wants to check for one outputclass (“border”) among many Challenge: There may also be a “borderless” outputclass, and the outputclass may appear among others (“border other”, “other border”, “otherA border otherB”) Solution 2 (XPath 2.0): <xsl:if  test= &quot;tokenize(@outputclass, ' ')[. = 'border']&quot; >   <xsl:attribute  name= &quot;border&quot; > 1pt solid black </xsl:attribute> </xsl:if>
Main Topics ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Keys Trademark Revisited Goal: A client wants the trademark symbol to appear only on the first usage of each trademark, but doesn’t want to take the performance hit of searching through the entire document each and every time a <tm> is processed Solution: <xsl:key  name= &quot;tm&quot;   match= &quot;*[contains(@class, ' topic/tm ')]&quot;  use= &quot;@trademark&quot; /> <xsl:if  test= &quot;generate-id(.) = generate-id(key('tm', @trademark)[1])&quot; > … </xsl:if>
Main Topics ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Grouping Goal: A client wants to group child links by type stage1.xml: <linkpool  class= &quot;- topic/linkpool &quot; >   <link  class= &quot;- topic/link &quot;  role= &quot;child&quot;  type= &quot;concept&quot; >   <linktext  class= &quot;- topic/linktext &quot; > Concept One </linktext>   <desc  class= &quot;- topic/desc &quot; > This is a concept topic. </desc>   </link>   <link  class= &quot;- topic/link &quot;  role= &quot;child&quot;  type= &quot;reference&quot; >   <linktext  class= &quot;- topic/linktext &quot; > Reference One </linktext>   <desc  class= &quot;- topic/desc &quot; > This is a reference topic. </desc>   </link>   <link  class= &quot;- topic/link &quot;  role= &quot;child&quot;  type= &quot;concept&quot; >   <linktext  class= &quot;- topic/linktext &quot; > Concept Two </linktext>   <desc  class= &quot;- topic/desc &quot; > This is another concept topic. </desc>   </link> </linkpool>
Grouping Solution 1 – Muenchian Method: <xsl:key  name= &quot;child-links&quot;  match= &quot;*[contains(@class, ' topic/link ') and @role='child']&quot;  use= &quot;@type&quot; />   <xsl:for-each  select= &quot;*[contains(@class, ' topic/link ') and @role = 'child'] [generate-id(.) = generate-id(key('child-links', @type)[1])&quot; >   <fo:block>   <xsl:value-of  select= &quot;ss:first-upper-case(@type)&quot; />   </fo:block>     <xsl:for-each  select= &quot;key('child-links', @type)&quot; > ...   </xsl:for-each>  </xsl:for-each>
Grouping Solution 2 (XPath 2.0): <xsl:for-each-group  select= &quot;*[contains(@class, ' topic/link ') and @role = 'child']&quot;   group-by= &quot;@type&quot; >   <fo:block>   <xsl:value-of  select= &quot;ss:first-upper-case(current-grouping-key())&quot; />   </fo:block>     <xsl:for-each  select= &quot;current-group()&quot; > ...   </xsl:for-each> </xsl:for-each-group>
Main Topics ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
End of Advanced XPATH ,[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

Lotusphere 2006 AD212 Introduction to DXL
Lotusphere 2006 AD212 Introduction to DXLLotusphere 2006 AD212 Introduction to DXL
Lotusphere 2006 AD212 Introduction to DXL
dominion
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
isadorta
 

What's hot (20)

XML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEARXML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEAR
 
Developing Plugins
Developing PluginsDeveloping Plugins
Developing Plugins
 
Component and Event-Driven Architectures in PHP
Component and Event-Driven Architectures in PHPComponent and Event-Driven Architectures in PHP
Component and Event-Driven Architectures in PHP
 
Object Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHPObject Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHP
 
The Big Documentation Extravaganza
The Big Documentation ExtravaganzaThe Big Documentation Extravaganza
The Big Documentation Extravaganza
 
XML Transformations With PHP
XML Transformations With PHPXML Transformations With PHP
XML Transformations With PHP
 
Xhtml
XhtmlXhtml
Xhtml
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
 
PEAR For The Masses
PEAR For The MassesPEAR For The Masses
PEAR For The Masses
 
XML and PHP 5
XML and PHP 5XML and PHP 5
XML and PHP 5
 
Session Server - Maintaing State between several Servers
Session Server - Maintaing State between several ServersSession Server - Maintaing State between several Servers
Session Server - Maintaing State between several Servers
 
Open Power Template 2 presentation
Open Power Template 2 presentationOpen Power Template 2 presentation
Open Power Template 2 presentation
 
CSS
CSSCSS
CSS
 
Design attern in php
Design attern in phpDesign attern in php
Design attern in php
 
Lotusphere 2006 AD212 Introduction to DXL
Lotusphere 2006 AD212 Introduction to DXLLotusphere 2006 AD212 Introduction to DXL
Lotusphere 2006 AD212 Introduction to DXL
 
PHP MySQL
PHP MySQLPHP MySQL
PHP MySQL
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Design Tools Html Xhtml
Design Tools Html XhtmlDesign Tools Html Xhtml
Design Tools Html Xhtml
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
 
Xhtml
XhtmlXhtml
Xhtml
 

Similar to AdvancedXPath

Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
Magecom Ukraine
 
StrategiesForUsingMetadata
StrategiesForUsingMetadataStrategiesForUsingMetadata
StrategiesForUsingMetadata
Suite Solutions
 
HTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowHTL(Sightly) - All you need to know
HTL(Sightly) - All you need to know
Prabhdeep Singh
 

Similar to AdvancedXPath (20)

Xml
XmlXml
Xml
 
3 xml namespaces and xml schema
3   xml namespaces and xml schema3   xml namespaces and xml schema
3 xml namespaces and xml schema
 
Struts2
Struts2Struts2
Struts2
 
5 xsl (formatting xml documents)
5   xsl (formatting xml documents)5   xsl (formatting xml documents)
5 xsl (formatting xml documents)
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
 
Struts2
Struts2Struts2
Struts2
 
XPath - XML Path Language
XPath - XML Path LanguageXPath - XML Path Language
XPath - XML Path Language
 
Web Designing
Web DesigningWeb Designing
Web Designing
 
Processing XML with Java
Processing XML with JavaProcessing XML with Java
Processing XML with Java
 
Xml Schema
Xml SchemaXml Schema
Xml Schema
 
Digital + Container List
Digital + Container ListDigital + Container List
Digital + Container List
 
HTML (Basic to Advance)
HTML (Basic to Advance)HTML (Basic to Advance)
HTML (Basic to Advance)
 
Week 12 xml and xsl
Week 12 xml and xslWeek 12 xml and xsl
Week 12 xml and xsl
 
StrategiesForUsingMetadata
StrategiesForUsingMetadataStrategiesForUsingMetadata
StrategiesForUsingMetadata
 
What is xml
What is xmlWhat is xml
What is xml
 
Play Template Engine Based On Scala
Play Template Engine Based On ScalaPlay Template Engine Based On Scala
Play Template Engine Based On Scala
 
Advance HTML
Advance HTMLAdvance HTML
Advance HTML
 
HTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowHTL(Sightly) - All you need to know
HTL(Sightly) - All you need to know
 
Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18
 
Mdst 3559-02-01-html
Mdst 3559-02-01-htmlMdst 3559-02-01-html
Mdst 3559-02-01-html
 

More from Suite Solutions

DITA Quick Start for Authors Part II
DITA Quick Start for Authors Part IIDITA Quick Start for Authors Part II
DITA Quick Start for Authors Part II
Suite Solutions
 
Dita ot pipeline webinar
Dita ot pipeline webinarDita ot pipeline webinar
Dita ot pipeline webinar
Suite Solutions
 
CustomizingStyleSheetsForHTMLOutputs
CustomizingStyleSheetsForHTMLOutputsCustomizingStyleSheetsForHTMLOutputs
CustomizingStyleSheetsForHTMLOutputs
Suite Solutions
 
Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...
Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...
Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...
Suite Solutions
 

More from Suite Solutions (20)

SuiteHelp 4.0: Latest Features in Enterprise Webhelp
SuiteHelp 4.0: Latest Features in Enterprise WebhelpSuiteHelp 4.0: Latest Features in Enterprise Webhelp
SuiteHelp 4.0: Latest Features in Enterprise Webhelp
 
Moving your Organization up the Knowledge Value Chain (Proposal for Lavacon 2...
Moving your Organization up the Knowledge Value Chain (Proposal for Lavacon 2...Moving your Organization up the Knowledge Value Chain (Proposal for Lavacon 2...
Moving your Organization up the Knowledge Value Chain (Proposal for Lavacon 2...
 
Increasing Findability with Subject Schemes (Advanced DITA Webinar)
Increasing Findability with Subject Schemes (Advanced DITA Webinar)Increasing Findability with Subject Schemes (Advanced DITA Webinar)
Increasing Findability with Subject Schemes (Advanced DITA Webinar)
 
SuiteHelp 3.2.5 Latest Features
SuiteHelp 3.2.5 Latest FeaturesSuiteHelp 3.2.5 Latest Features
SuiteHelp 3.2.5 Latest Features
 
Using Taxonomy for Customer-centric Dynamic Publishing
Using Taxonomy for Customer-centric Dynamic PublishingUsing Taxonomy for Customer-centric Dynamic Publishing
Using Taxonomy for Customer-centric Dynamic Publishing
 
DITA Quick Start Webinar: Defining Your Style Sheet Requirements
DITA Quick Start Webinar: Defining Your Style Sheet RequirementsDITA Quick Start Webinar: Defining Your Style Sheet Requirements
DITA Quick Start Webinar: Defining Your Style Sheet Requirements
 
DITA Quick Start Webinar Series: Building a Project Plan
DITA Quick Start Webinar Series: Building a Project PlanDITA Quick Start Webinar Series: Building a Project Plan
DITA Quick Start Webinar Series: Building a Project Plan
 
DITA Quick Start Webinar Series: Building a Project Plan
DITA Quick Start Webinar Series: Building a Project PlanDITA Quick Start Webinar Series: Building a Project Plan
DITA Quick Start Webinar Series: Building a Project Plan
 
DITA Quick Start: System Architecture of a Basic DITA Toolset
DITA Quick Start: System Architecture of a Basic DITA ToolsetDITA Quick Start: System Architecture of a Basic DITA Toolset
DITA Quick Start: System Architecture of a Basic DITA Toolset
 
DITA Quick Start Webinar Series: Getting Started with the DITA Open Toolkit
DITA Quick Start Webinar Series: Getting Started with the DITA Open ToolkitDITA Quick Start Webinar Series: Getting Started with the DITA Open Toolkit
DITA Quick Start Webinar Series: Getting Started with the DITA Open Toolkit
 
DITA Quick Start Webinar Series: Getting Started with Information Architecture
DITA Quick Start Webinar Series: Getting Started with Information ArchitectureDITA Quick Start Webinar Series: Getting Started with Information Architecture
DITA Quick Start Webinar Series: Getting Started with Information Architecture
 
Introduction to S1000D
Introduction to S1000DIntroduction to S1000D
Introduction to S1000D
 
DITA Quick Start for Authors Part II
DITA Quick Start for Authors Part IIDITA Quick Start for Authors Part II
DITA Quick Start for Authors Part II
 
DITA Quick Start for Authors - Part I
DITA Quick Start for Authors - Part IDITA Quick Start for Authors - Part I
DITA Quick Start for Authors - Part I
 
Suite Labs: Generating SuiteHelp Output
Suite Labs: Generating SuiteHelp OutputSuite Labs: Generating SuiteHelp Output
Suite Labs: Generating SuiteHelp Output
 
Overview of SuiteHelp 3.1 for DITA
Overview of SuiteHelp 3.1 for DITAOverview of SuiteHelp 3.1 for DITA
Overview of SuiteHelp 3.1 for DITA
 
Svg and graphics
Svg and graphicsSvg and graphics
Svg and graphics
 
Dita ot pipeline webinar
Dita ot pipeline webinarDita ot pipeline webinar
Dita ot pipeline webinar
 
CustomizingStyleSheetsForHTMLOutputs
CustomizingStyleSheetsForHTMLOutputsCustomizingStyleSheetsForHTMLOutputs
CustomizingStyleSheetsForHTMLOutputs
 
Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...
Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...
Understanding and Configuring the FO Plug-in for Generating PDF Files: Part I...
 

Recently uploaded

Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Recently uploaded (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 

AdvancedXPath

  • 1. Advanced XPath and XSLT Reuven Weiser, Suite Solutions
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. Basic Example From commons.xsl: <xsl:template match= &quot;*[contains(@class,' topic/fig ')]&quot; > <fo:block xsl:use-attribute-sets= &quot;fig&quot; id= &quot;{@id}&quot; > <xsl:apply-templates select= &quot;*[not(contains(@class,' topic/title '))]&quot; /> <xsl:apply-templates select= &quot;*[contains(@class,' topic/title ')]&quot; /> </fo:block> </xsl:template>
  • 10. XPath Abbreviations Expression Description Nodename Selects named node / Selects from the root node (start of expression) or the current node // Selects any descendant of the root node (start of expression) or the current node . Selects the current node .. Selects the parent of the current node @ Selects attributes * Wildcard – matches any element node() Matches any node of any kind [ ] Brackets that contain a predicate, which is used to find a specific node
  • 11.
  • 12. List Numbering Goal: A client wants <ol>s in <fig>s to be uppercase-lettered, and sub-<ol>s to be lowercase-lettered Solution: <xsl:choose> <xsl:when test= &quot;ancestor::*[contains(@class, ' topic/fig ')]&quot; > <xsl:number format= &quot;A&quot; /> </xsl:when> <xsl:when test= &quot;count(ancestor::*[contains(@class, ' topic/ol ')]) > 1&quot; > <xsl:number format= &quot;a&quot; /> </xsl:when> <xsl:otherwise> <xsl:number/> </xsl:otherwise> </xsl:choose>
  • 13. List Numbering Technique Note Instead of: <xsl:when test= &quot;ancestor::*[contains(@class, ' topic/fig ')]&quot; > We could say: <xsl:when test= &quot;ancestor::fig&quot; > But: That wouldn’t account for specialization!
  • 14.
  • 15. Trademarks and current() Goal: A client wants the trademark symbol to appear only on the first usage of each trademark Solution 1: <xsl:variable name= &quot;trademark&quot; select= &quot;@trademark&quot; /> <xsl:if test= &quot;not(preceding::*[contains(@class, ' topic/tm ') and @trademark = $trademark)&quot; > ... </xsl:if> Solution 2 (XPath 2.0): <xsl:if test= &quot;not(preceding::*[contains(@class, ' topic/tm ') and @trademark = current()/@trademark)&quot; > ... </xsl:if>
  • 16.
  • 17. Custom Functions Goal: A client wants to convert certain text strings to Title Case Solution: <xsl:stylesheet xmlns:xsl= &quot;http://www.w3.org/1999/XSL/Transform&quot; xmlns:ss= &quot;http://www.suite-sol.com&quot; version= &quot;1.1&quot; > <xsl:function name= &quot;ss:first-upper-case&quot; > <xsl:param name= &quot;string&quot; /> <xsl:value-of select= &quot;concat(upper-case(substring($string, 1, 1)), lower-case(substring($string, 2)))&quot; /> </xsl:function>
  • 18. Custom Functions Goal: A client to convert certain text strings to Title Case Solution (continued): <xsl:function name= &quot;ss:title-case&quot; > <xsl:param name= &quot;string&quot; /> <xsl:choose> <xsl:when test= &quot;contains($string, ' ')&quot; > <xsl:value-of select= &quot;concat(ss:first-upper-case(substring-before($string, ' ')), ' ', ss:title-case(substring-after($string), ' '))&quot; /> </xsl:when> <xsl:otherwise> <xsl:value-of select= &quot;ss:first-upper-case($string)&quot; /> </xsl:otherwise> </xsl:choose> </xsl:function> <xsl:value-of select= &quot;ss:title-case($stringToConvert)&quot; />
  • 19.
  • 20. tokenize() Goal: A client wants to check for one outputclass (“border”) among many Challenge: There may also be a “borderless” outputclass, and the outputclass may appear among others (“border other”, “other border”, “otherA border otherB”) Solution 1: <xsl:if test= &quot;(@outputclass = 'border') or starts-with(@outputclass, 'border ') or contains(@outputclass, ' border ') or (substring(@outputclass, string-length(@outputclass)-6, 7)= ' border')&quot; > <xsl:attribute name= &quot;border&quot; > 1pt solid black </xsl:attribute> </xsl:if>
  • 21. tokenize() Goal: A client wants to check for one outputclass (“border”) among many Challenge: There may also be a “borderless” outputclass, and the outputclass may appear among others (“border other”, “other border”, “otherA border otherB”) Solution 2 (XPath 2.0): <xsl:if test= &quot;tokenize(@outputclass, ' ')[. = 'border']&quot; > <xsl:attribute name= &quot;border&quot; > 1pt solid black </xsl:attribute> </xsl:if>
  • 22.
  • 23. Keys Trademark Revisited Goal: A client wants the trademark symbol to appear only on the first usage of each trademark, but doesn’t want to take the performance hit of searching through the entire document each and every time a <tm> is processed Solution: <xsl:key name= &quot;tm&quot; match= &quot;*[contains(@class, ' topic/tm ')]&quot; use= &quot;@trademark&quot; /> <xsl:if test= &quot;generate-id(.) = generate-id(key('tm', @trademark)[1])&quot; > … </xsl:if>
  • 24.
  • 25. Grouping Goal: A client wants to group child links by type stage1.xml: <linkpool class= &quot;- topic/linkpool &quot; > <link class= &quot;- topic/link &quot; role= &quot;child&quot; type= &quot;concept&quot; > <linktext class= &quot;- topic/linktext &quot; > Concept One </linktext> <desc class= &quot;- topic/desc &quot; > This is a concept topic. </desc> </link> <link class= &quot;- topic/link &quot; role= &quot;child&quot; type= &quot;reference&quot; > <linktext class= &quot;- topic/linktext &quot; > Reference One </linktext> <desc class= &quot;- topic/desc &quot; > This is a reference topic. </desc> </link> <link class= &quot;- topic/link &quot; role= &quot;child&quot; type= &quot;concept&quot; > <linktext class= &quot;- topic/linktext &quot; > Concept Two </linktext> <desc class= &quot;- topic/desc &quot; > This is another concept topic. </desc> </link> </linkpool>
  • 26. Grouping Solution 1 – Muenchian Method: <xsl:key name= &quot;child-links&quot; match= &quot;*[contains(@class, ' topic/link ') and @role='child']&quot; use= &quot;@type&quot; /> <xsl:for-each select= &quot;*[contains(@class, ' topic/link ') and @role = 'child'] [generate-id(.) = generate-id(key('child-links', @type)[1])&quot; > <fo:block> <xsl:value-of select= &quot;ss:first-upper-case(@type)&quot; /> </fo:block> <xsl:for-each select= &quot;key('child-links', @type)&quot; > ... </xsl:for-each> </xsl:for-each>
  • 27. Grouping Solution 2 (XPath 2.0): <xsl:for-each-group select= &quot;*[contains(@class, ' topic/link ') and @role = 'child']&quot; group-by= &quot;@type&quot; > <fo:block> <xsl:value-of select= &quot;ss:first-upper-case(current-grouping-key())&quot; /> </fo:block> <xsl:for-each select= &quot;current-group()&quot; > ... </xsl:for-each> </xsl:for-each-group>
  • 28.
  • 29.

Editor's Notes

  1. Suite Solutions: DITA Quick Start Training for Authors iDTP, March 16-18, 2009