code_junkie

Build a regular expression to find id in an href

Nov 12th, 2011
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <?dctm xml_app="elearningContent"?>
  3. <!DOCTYPE OnlineContent PUBLIC "-//ISDOFSD//DTD Online Content//EN" "file:C:/dmExport/New%20Folder%20(2)/ISDOFSDdev/elearningContent/OnlineContent.dtd">
  4. <OnlineContent outputclass="Graphic Down" id="OnlineContent_955627C91D8743B98DCB8BD9BE379DE8">
  5. <title>Text and Popup</title>
  6. <OnlineContentBody>
  7. <lcInstruction id="lcInstruction_770F26218C064A84BFA1813562173970">
  8. <p>This is an example of a plain text screen with an attached popup.</p>
  9. <p>
  10. Popups are used to display additional content in a popup window. A <xref scope="local" type="topic" format="dita" href="dctm://ISDOFSDdev/37004e1f800021f3?DMS_OBJECT_SPEC=RELATION_ID">link is provided</xref> in the main text of the screen, which may clicked on to open a popup. A screen may contain <xref scope="local" type="topic" format="dita" href="dctm://ISDOFSDdev/37004e1f800021f4?DMS_OBJECT_SPEC=RELATION_ID">more than one popup</xref>.
  11. </p>
  12. </lcInstruction>
  13. </OnlineContentBody>
  14. <OnlinePopup id="OnlinePopup_AFE53E2CACBF4D8196E6360D4DDB6B70">
  15. <title>A Popup</title>
  16. <OnlinePopupBody>
  17. <p>This is an example of popup content.</p>
  18. <p>A popup may contain one or more paragraphs of text. They may also contain lists, like this:</p>
  19. <ul id="ul_7812991BBBDD4995B7499A9557C4EA9C">
  20. <li id="li_E83BDB28EC494B98BFF3DD5924AF855E">An item in a list</li>
  21. <li id="li_270F2A3A85BA4E6EBF98CB4023344475">Another item in a list</li>
  22. </ul>
  23. <p>A numbered list is demonstrated in the second popup.</p>
  24. </OnlinePopupBody>
  25. </OnlinePopup>
  26. <OnlinePopup id="OnlinePopup_5AE081BFB97043CE99F39A9E4A063332">
  27. <title>Another Popup</title>
  28. <OnlinePopupBody>
  29. <p>This is the second popup on this screen, containing a numbered list.</p>
  30. <ol id="ol_EF18C080E7CC40B7998DEB75772367A6">
  31. <li id="li_91B42F1B886B4CF887C001577C14B3F0">An item in a list</li>
  32. <li id="li_95C4F32E093843FAB985A3F6981A7D07">Another item in a list</li>
  33. </ol>
  34. </OnlinePopupBody>
  35. </OnlinePopup>
  36. </OnlineContent>
  37.  
  38. [a-fA-F0-9]+(?=?DMS_OBJECT_SPEC=RELATION_ID)
  39.  
  40. <?xml version="1.0"?>
  41. <xsl:stylesheet version="1.0"
  42. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  43. >
  44. <xsl:output method="text" indent="no"/>
  45. <xsl:template match="*[@href]">
  46. <xsl:if test="contains(@href, 'RELATION_ID')">
  47. <xsl:value-of select="@href"/>
  48. <xsl:text>&#xa;</xsl:text>
  49. </xsl:if>
  50. <xsl:apply-templates select="*"/>
  51. </xsl:template>
  52. <xsl:template match="*">
  53. <xsl:apply-templates select="*"/>
  54. </xsl:template>
  55. </xsl:stylesheet>
  56.  
  57. C:Documents and SettingsferEscritorio>msxsl.exe -xw example.xml example-xslt.xsl > out.txt
  58.  
  59. <?xml version="1.0"?>
  60. <xsl:stylesheet version="1.0"
  61. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  62. xmlns:fn="http://www.w3.org/2005/xpath-functions" >
  63. <xsl:output method="text" indent="no"/>
  64. <xsl:template match="*[@href]">
  65. <xsl:if test="fn:contains(@href, 'RELATION_ID')">
  66. <xsl:value-of select="fn:replace(@href,'.*/([^/]*)?.*', '$1')"/>
  67. <xsl:text>&#xa;</xsl:text>
  68. </xsl:if>
  69. <xsl:apply-templates select="*"/>
  70. </xsl:template>
  71. <xsl:template match="*">
  72. <xsl:apply-templates select="*"/>
  73. </xsl:template>
  74. </xsl:stylesheet>
  75.  
  76. C:Documents and SettingsferEscritorio>AltovaXML -xslt2 example-xslt.xsl -in example.xml
  77.  
  78. expr = re.compile('href=.*?/(.*?)?.*?=RELATION_ID', re.MULTILINE)
  79.  
  80. for x in expr.finditer(test_string): # iterate through all matches
  81. s = x.group(1) # get the one and only group of the match
  82. ss = s.split("/") # split off the ISDOFSDdev
  83. s = ss[len(ss) - 1] # grab the last element
  84. print s # print it
  85.  
  86. 37004e1f800021f3
  87. 37004e1f800021f4
Add Comment
Please, Sign In to add comment