Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML/Sechma/XSLT技術.

Similar presentations


Presentation on theme: "XML/Sechma/XSLT技術."— Presentation transcript:

1 XML/Sechma/XSLT技術

2 大綱 電子病歷標準制定過程 CDA R2實作問題 XML技術簡介 XML Schema技術 XSLT技術 XSLT語法 XPATH語法
編寫技巧

3 電子病歷標準制定過程

4 背景說明 為什麼醫療院所需要知道電子病歷標準制定流程? 108張夠用嗎? 不夠?那到底要幾張? 那弄2000張好了? 誰來定,誰付錢?
就算衛生署買單,那你買帳嗎?

5 電子病歷標準設計流程 紙本病歷 欄位需求清單 xls/doc 實作指引標準書 doc/PDF 整理 定義 設計 需求 規則 結構定義檔
xsd 參照 內容驗證檔 sch 規範 XML範例 xml 欄位變數對應檔 xsl XPath 驗證用編碼 比照 匯入 除錯 病歷呈現樣式檔html 呈現樣式轉換檔 xsl 字彙控制檔 xml 複製 呈現用編碼

6 紙本病歷 由需求單位提出

7 欄位需求清單 xls/doc 由病歷管理單位整理 並經電子病歷委員會認可

8 實作指引標準書 doc/PDF 由標準管理單位編寫 若是全國通用,則可至電子病歷標準管理系統下載。

9 病歷呈現樣式檔html 由實作執行單位與病歷管理單位共同合作編寫

10 結構定義檔 xsd 此為CDA R2標準文件。 由實作執行單位從電子病歷標準管理系統下載取得。

11 XML範例 xml 由標準管理單位與實作執行單位共同編輯設計。

12 欄位變數對應檔 xsl 由下列三個單位共同設計: 病歷管理單位 標準管理單位 實作執行單位

13 呈現樣式轉換檔 xsl 可由電子病歷標準管理系統下載參考。 實作執行單位編輯設計。

14 字彙控制檔 xml 可經由電子病歷標準管理系統取得。 由標準管理單位負責維護。 由實作執行單位負責編輯。

15 內容驗證檔 sch 由實作執行單位依據實作指引標準書之內容編輯。 若為全國通用者,則可至電子病歷標準管理系統下載。

16 最後成果

17 電子病歷實作問題

18 實踐電子病歷之問題所在 電子病歷設計管理 電子病歷文件管理 電子病歷流程管理 電子病歷應用管理

19 專注在「產生」電子病歷文件

20 實作可能模式 XML編輯器 電子表單軟體 SOA/EAI工具 程式設計
軟體有:微軟XML Notepad 2007、Altova XML SPY、oXygenXML等。 對終端使用者不友善。 電子表單軟體 軟體有:微軟InfoPath、Adobe等 可設計符合使用者介面之資料輸入介面。 SOA/EAI工具 軟體工具很多。微軟BizTalk。 須從系統流程整合角度切入使用。 程式設計 可配合實際需求撰寫。 需要程式設計開發人員。

21 V3 CDA 技術簡述 – 標準類 臨床類: 技術類: HL7類: RIM 、DataType、Vocabulary、RMIM、CDA
POCD_MT xsd CDA.xsd NarrativeBlock.xsd datatypes.xsd datatypes-base.xsd voc.xsd CDA V3 entries narrative header namespaces body 區段 臨床類: LOINC:文件類型與區段代碼。 SNOMED:區段內容代碼。 ICD:區段內容代碼。 其他:如藥品等,區段內容代碼。 技術類: XHTML:臨床文件呈現格式 CSS:XHTML呈現樣式 XML:臨床文件儲存格式 SCHEMA:XML結構驗證 SCHEMATRON:XML內容驗證 XSLT:XML轉成XHTML XPATH:定義XML各元素之位置(XSLT與Schematron中會用到) HL7類: RIM 、DataType、Vocabulary、RMIM、CDA

22 Cda r2與資料來源的關係 資料 來源 資料 來源 資料庫 不變值:資料來源是如何就如何。如姓名。 表單
訊息 檔案 限定值:資料來源需經過轉碼。如性別。 系統值:由CDA R2程式所產生。如文件產生時間。 資料 來源 固定值:由CDA R2決定。只要是實作CDA R2就是這個碼。如typeID 預設值:由實作指引標準書決定。只要實作哪份單張就會決定碼。如code

23 基本概念 CDA XSLT HTML

24 XML技術簡介

25 什麼是XML XML 是指eXtensible Markup Language。 XML 是設計用來攜帶資料,不是顯示資料之用。
XML的標籤( tag)並未事先定義,你必須設計定義自 己的標籤。 XML被設計為可以自我描述內容。 XML是W3C 所推薦標準。

26 簡單的XML範例 <note> <to>同學</to> <from>老師</from> <heading>注意事項</heading> <body>下週二小考</body> </note> 注意: XML沒有特殊規範,只是一個文字檔。 你可以自行創造各種標籤名稱。 他提供了一種與軟體、硬體獨立的交換情境。

27 XML衍生之應用 在網際網路上,因為XML而擴展之應用 XHTML the latest version of HTML
WSDL for describing available web services WAP and WML as markup languages for handheld devices RSS languages for news feeds RDF and OWL for describing resources and ontology SMIL for describing multimedia for the web

28 XML在產業的應用 http://www.oasis-open.org/cover/xml.html#applications
Web Servers: apacheXML parsers, XSL, web publishing Travel: openTravel information for airlines, hotels, and car rental places News: NewsML creation, transfer and delivery of news Voice: VoxML markup language for voice applications Wireless: WAP (Wireless Application Protocol) wireless devices on the World Wide Web Weather: OMF Weather Observation Markup Format (simulation) Healthcare: HL7 DTDs for prescriptions, policies & procedures, clinical trials Math: MathML (Mathematical Markup Language)

29 術語說明 Root element type element type element Attribute (name,value)
<bibliography> <paper ID="object-fusion"> <authors> <author>Y.Papakonstantinou</author> <author>S. Abiteboul</author> <author>H. Garcia-Molina</author> </authors> <fullPaper source="fusion"/> <title>Object Fusion in Mediator Systems</title> <booktitle>VLDB 96</booktitle> </paper> </bibliography> element content Empty element character content

30 XML之規則 All XML Elements Must Have a Closing Tag
XML Tags are Case Sensitive XML Elements Must be Properly Nested <p>This is a paragraph</p> <p>This is another paragraph</p> <Message>This is incorrect</message> <message>This is correct</message> <b><i>This text is bold and italic</i></b>

31 XML之規則 XML Documents Must Have a Root Element
XML Attribute Values Must be Quoted Entity References <root>   <child>     <subchild>.....</subchild>   </child> </root> <note date="12/11/2007">   <to>Tove</to>   <from>Jani</from> </note> < < less than > > greater than & & ampersand  ' ' apostrophe " “ quotation mark

32 XML之規則 Comments in XML White-space is Preserved in XML
XML Stores New Line as LF <!-- This is a comment -->

33 XML之驗證 Well Formed XML Documents Valid XML Documents XML Namespaces
XML documents must have a root element XML elements must have a closing tag XML tags are case sensitive XML elements must be properly nested XML attribute values must be quoted Valid XML Documents 符合DTD規範或 XML Schema XML Namespaces identify your vocabulary

34 XML Schema技術

35 為什麼需要xml schema

36

37 XML與schema

38 建立schema檔 Xml文件宣告 建立root element 宣告namespace
<?xml version=“1.0”?> 建立root element <xs:schema > 宣告namespace

39 Xml檔案之引用

40 Xml Schema 的註解 透過xml編輯器,可以將此段文字顯示出來。有即時 說明的作用。

41 定義簡易型態元素 正確 錯誤

42 簡易型態

43 固定值與預設值 Valid No valid

44 自定簡易型態 在元素中定義 可重複使用

45 限定範圍值 ─ 列舉

46 複雜型態

47 基本說明 Xml的元素可以分成簡單型態與複雜型態 複雜型態又可以在分成簡單內容與複雜內容 Xml範例
屬於複雜型態的元素,可以有子元素與屬性。 簡單型態不行有子元素與屬性。 複雜型態又可以在分成簡單內容與複雜內容 簡單內容就只能放字串。 複雜內容則可以有子元素。 Xml範例

48 定義子元素 In order

49 定義子元素 In any order

50 定義子元素 Choices

51 參照全域變數

52 控制次數

53 定義屬性

54 Xslt技術

55 什麼是XSLT eXtensible Stylesheet Language for Transformations
Language for transforming XML documents A programming language for XML documents A functional language, based on value substitution Augmented with pattern matching And also template substitution to construct output (based on namespaces Uses XML syntax

56 常見應用 XML to HTML— for old browsers XML to LaTeX—for TeX layout
XML to SVG—graphs, charts, trees XML to tab-delimited—for db/stat packages XML to plain-text—occasionally useful XML to FO—XSL formatting objects

57 簡單範例 File data.xml: File render.xsl:
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="render.xsl"?> <message>Howdy!</message> File render.xsl: <?xml version="1.0"?> <xsl:stylesheet version="1.0” xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- one rule, to transform the input root (/) --> <xsl:template match="/"> <html><body> <h1><xsl:value-of select="message"/></h1> </body></html> </xsl:template> </xsl:stylesheet>

58 XSLT語法

59 The .xsl file An XSLT document has the .xsl extension
The XSLT document begins with: <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/ XSL/Transform"> Contains one or more templates, such as: <xsl:template match="/"> ... </xsl:template> And ends with: </xsl:stylesheet>

60 Finding the message text
The template <xsl:template match="/"> says to select the entire file You can think of this as selecting the root node of the XML tree Inside this template, <xsl:value-of select="message"/> selects the message child Alternative Xpath expressions that would also work: ./message /message/text() (text() is an XPath function) ./message/text()

61 Putting it together The XSL was: <xsl:template match="/"> <html><body> <h1><xsl:value-of select="message"/></h1> </body></html> </xsl:template> The <xsl:template match="/"> chooses the root The <html><body> <h1> is written to the output file The contents of message is written to the output file The </h1> </body></html> is written to the output file The resultant file looks like: <html><body> <h1>Howdy!</h1> </body></html>

62 How XSLT works The XML text document is read in and stored as a tree of nodes The <xsl:template match="/"> template is used to select the entire tree The rules within the template are applied to the matching nodes, thus changing the structure of the XML tree If there are other templates, they must be called explicitly from the main template Unmatched parts of the XML tree are not changed After the template is applied, the tree is written out again as a text document

63 Where XSLT can be used With an appropriate program, such as Xerces, XSLT can be used to read and write files A server can use XSLT to change XML files into HTML files before sending them to the client A modern browser can use XSLT to change XML into HTML on the client side This is what we will mostly be doing in this class Most users seldom update their browsers If you want “everyone” to see your pages, do any XSL processing on the server side Otherwise, think about what best fits your situation

64 Modern browsers Internet Explorer 6 best supports XML
Netscape 6 supports some of XML Internet Explorer 5.x supports an obsolete version of XML IE5 is not good enough for this course If you must use IE5, the initial PI is different (you can look it up if you ever need it)

65 xsl:value-of <xsl:value-of select="XPath expression"/> selects the contents of an element and adds it to the output stream The select attribute is required Notice that xsl:value-of is not a container, hence it needs to end with a slash Example (from an earlier slide): <h1> <xsl:value-of select="message"/> </h1>

66 xsl:for-each xsl:for-each is a kind of loop statement
The syntax is <xsl:for-each select="XPath expression"> Text to insert and rules to apply </xsl:for-each> Example: to select every book (//book) and make an unordered list (<ul>) of their titles (title), use: <ul> <xsl:for-each select="//book"> <li> <xsl:value-of select="title"/> </li> </xsl:for-each> </ul>

67 Filtering output You can filter (restrict) output by adding a criterion to the select attribute’s value: <ul> <xsl:for-each select="//book"> <li> <xsl:value-of select="title[../author='Terry Pratchett']"/> </li> </xsl:for-each> </ul> This will select book titles by Terry Pratchett

68 Filter details Here is the filter we just used: <xsl:value-of select="title[../author='Terry Pratchett'"]/> author is a sibling of title, so from title we have to go up to its parent, book, then back down to author This filter requires a quote within a quote, so we need both single quotes and double quotes Legal filter operators are: = != < > Numbers should be quoted, but apparently don’t have to be

69 But it doesn’t work right!
Here’s what we did: <xsl:for-each select="//book"> <li> <xsl:value-of select="title[../author='Terry Pratchett']"/> </li> </xsl:for-each> This will output <li> and </li> for every book, so we will get empty bullets for authors other than Terry Pratchett There is no obvious way to solve this with just xsl:value-of

70 xsl:if xsl:if allows us to include content if a given condition (in the test attribute) is true Example: <xsl:for-each select=“//book”> <xsl:if test=“author=‘Terry Pratchett’”> <li><xsi:text>作者</xsi:text> <xsl:value-of select="title"/> </li> </xsl:if> </xsl:for-each> This does work correctly!

71 xsl:choose • xsl:choose is often used within an xsl:for-each loop
The xsl:choose ... xsl:when ... xsl:otherwise construct is XML’s equivalent of Java’s switch ... case ... default statement The syntax is: <xsl:choose> <xsl:when test="some condition"> some code </xsl:when> <xsl:otherwise> some code </xsl:otherwise> </xsl:choose> • xsl:choose is often used within an xsl:for-each loop

72 xsl:sort You can place an xsl:sort inside an xsl:for-each
The attribute of the sort tells what field to sort on Example: <ul> <xsl:for-each select="//book"> <xsl:sort select="author"/> <li> <xsl:value-of select="title"/> by <xsl:value-of select="author"> </li> </xsl:for-each> </ul> This example creates a list of titles and authors, sorted by author

73 xsl:text <xsl:text>...</xsl:text> helps deal with two common problems: XSL isn’t very careful with whitespace in the document This doesn’t matter much for HTML, which collapses all whitespace anyway (though the HTML source may look ugly) <xsl:text> gives you much better control over whitespace; it acts like the <pre> element in HTML Since XML defines only five entities, you cannot readily put other entities (such as  ) in your XSL &nbsp; almost works, but   is visible on the page Here’s the secret formula for entities: <xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>

74 XPATH技術

75 What is XPath? XPath is a syntax used for selecting parts of an XML document The way XPath describes paths to elements is similar to the way an operating system describes paths to files XPath is almost a small programming language; it has functions, tests, and expressions XPath is a W3C standard XPath is not itself written as XML, but is used heavily in XSLT

76 重要術語 <library> <book> <chapter> </chapter> <chapter> <section> <paragraph/> <paragraph/> </section> </chapter> </book> </library> library is the parent of book; book is the parent of the two chapters The two chapters are the children of book, and the section is the child of the second chapter The two chapters of the book are siblings (they have the same parent) library, book, and the second chapter are the ancestors of the section The two chapters, the section, and the two paragraphs are the descendents of the book

77 路徑描述 Operating system: XPath: / = the root directory
/library = the root element (if named library ) /users/dave/foo = the file named foo in dave in users /library/book/chapter/section = every section element in a chapter in every book in the library foo = the file named foo in the current directory section = every section element that is a child of the current element . = the current directory . = the current element .. = parent of the current element .. = the parent directory /users/dave/* = all the files in /users/dave /library/book/chapter/* = all the elements in /library/book/chapter

78 斜線應用 A path that begins with a / represents an absolute path, starting from the top of the document Example: / /message/header/from Note that even an absolute path can select more than one element A slash by itself means “the whole document” A path that does not begin with a / represents a path starting from the current element Example: header/from A path that begins with // can start from anywhere in the document Example: //header/from selects every element from that is a child of an element header This can be expensive, since it involves searching the entire document

79 中括弧與last()函數 A number in brackets selects a particular matching child (counting starts from 1, except in Internet Explorer) Example: /library/book[1] selects the first book of the library Example: //chapter/section[2] selects the second section of every chapter in the XML document Example: //book/chapter[1]/section[2] Only matching elements are counted; for example, if a book has both sections and exercises, the latter are ignored when counting sections The function last() in brackets selects the last matching child Example: /library/book/chapter[last()] You can even do simple arithmetic Example: /library/book/chapter[last()-1]

80 星號應用 A star, or asterisk, is a “wild card”--it means “all the elements at this level” Example: /library/book/chapter/* selects every child of every chapter of every book in the library Example: //book/* selects every child of every book (chapters, tableOfContents, index, etc.) Example: /*/*/*/paragraph selects every paragraph that has exactly three ancestors Example: //* selects every element in the entire document

81 取屬性 i You can select attributes by themselves, or elements that have certain attributes Remember: an attribute consists of a name-value pair, for example in <chapter num="5">, the attribute is named num To choose the attribute itself, prefix the name will choose every attribute named num Example: will choose every attribute, everywhere in the document To choose elements that have a given attribute, put the attribute name in square brackets Example: will select every chapter element (anywhere in the document) that has an attribute named num

82 取屬性 ii selects every chapter element with an attribute num selects every chapter element that does not have a num attribute selects every chapter element that has any attribute selects every chapter element with no attributes

83 屬性值 selects every chapter element with an attribute num with value 3 selects every chapter element that does not have a num attribute selects every chapter element that has any attribute selects every chapter element with no attributes The normalize-space() function can be used to remove leading and trailing spaces from a value before comparison Example:

84 軸(axis)的概念 An axis (plural axes) is a set of nodes relative to a given node; X::Y means “choose Y from the X axis” self:: is the set of current nodes (not too useful) self::node() is the current node child:: is the default, so /child::X is the same as /X parent:: is the parent of the current node ancestor:: is all ancestors of the current node, up to and including the root descendant:: is all descendants of the current node (Note: never contains attribute or namespace nodes) preceding:: is everything before the current node in the entire XML document following:: is everything after the current node in the entire XML document

85 軸範例 Starting from a given node, the self, preceding, following, ancestor, and descendant axes form a partition of all the nodes (if we ignore attribute and namespace nodes) <library> <book> <chapter/> <chapter> <section> <paragraph/> <paragraph/> </section> </chapter> <chapter/> </book> <book/> </library> //chapter[2]/self::* //chapter[2]/preceding::* //chapter[2]/following::* //chapter[2]/ancestor::* //chapter[2]/descendant::*

86 算數式 + add - subtract * multiply div (not /) divide
mod modulo (remainder)

87 等式測試 = “equals” (Notice it’s not ==) != “not equals”
But it’s not that simple! value = node-set will be true if the node-set contains any node with a value that matches value value != node-set will be true if the node-set contains any node with a value that does not match value Hence, value = node-set and value != node-set may both be true at the same time!

88 其他布林運算子 and (infix operator) or (infix operator) not() (function)
Example: count = 0 or count = 1 not() (function) The following are used for numerical comparisons only: < “less than” Some places may require < <= “less than Some places may require <= or equal to” > “greater than” Some places may require > >= “greater than Some places may require >= or equal to”

89 感 謝 聆 聽 電子病歷是一門學問 不是一項技術


Download ppt "XML/Sechma/XSLT技術."

Similar presentations


Ads by Google